给出以下代码: 5.class Atom { 6. Atom() { System.out.print("atom"); } 7. } 8. class Rock extends Atom { 9. Rock(String type) {System.out.print(type); } 10. } 11. public class Mountain extends Rock { 12. Mountain() { 13. super("granite "); 14. new Rock("granite "); 15. } 16. public static void main(String[] a) { 17. new Mountain(); } 18. } 程序的执行结果是:( )
举一反三
- import java.io.*; class Person{ public void print(){System.out.print("Person ");} public void printMyGender(String s){ this.print(); System.out.print(s+" "); } } class Gender{ String type="gender"; public void print(Person p){p.printMyGender(type);} } class Female extends Gender{ public Female(){ type="female"; } } class Male extends Gender{ public Male(){ type="male"; } } class Employee extends Person{ public void print(){ System.out.print("Employee ");} } class Manager extends Employee{ public void print(){ System.out.print("Manager ");} } public class Test{ public static void main(String[] args){ Manager man = new Manager(); Employee em = new Employee(); Gender gender1 = new Male(); Gender gender2 = new Female(); gender1.print(man); gender2.print(em); } } 对于以上代码,其运行结果是
- (7-1)以下程序的运行结果是( )。 class A{ A(){ System.out.print(10); } } public class Demo extends A { public static void main(String[] args) { new A(); new Demo(); } }
- Java程序如下 class A{ public A(){System.out.print("A");} } class B extends A{ public B(){System.out.print("B");} public static void main(String[]s){ new B(); } } 该程序将( )。
- 对于一下程序,其运行结果为 class Base{ public Base(){ System.out.print("C"); } } class Base2 extends Base{ public Base2(){ System.out.print("B"); } } public class TestDemo extends Base2{ int m=1; public TestDemo(){ System.out.println("A"); } public static void main(String args[]){ TestDemo t = new TestDemo(); } }
- 编译并运行下面的程序,结果是 public class A { public static void main(String args[]) { B b = new B(); b.test(); } void test() { System.out.print("A"); } } class B extends A { void test() { super.test(); System.out.println("B"); } }