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); } } 对于以上代码,其运行结果是
举一反三
- 已知</p></p><p><p> import java.io.*;</p></p><p><p>class Person{</p></p><p><p>public static void print(){System.out.print("Person");}</p></p><p><p>}</p></p><p><p> class Employee extends Person{</p></p><p><p> public void print(){</p></p><p><p> System.out.print("Employee");}</p></p><p><p>}</p></p><p><p>class Manager extends Employee{</p></p><p><p> public void print(){</p></p><p><p> System.out.print("Manager");}</p></p><p><p>}</p></p><p><p>public class Test{</p></p><p><p> public static void main(String[] args){</p></p><p><p> Manager man = new Manager();</p></p><p><p> Employee emp1 = new Employee();</p></p><p><p> Employee emp2 = (Employee)man;</p></p><p><p> Person person = (Person)man;</p></p><p><p> emp2.print();</p></p><p><p> System.out.print("#");</p></p><p><p> person.print();}</p></p><p><p>}</p></p><p><p>对于以上代码,其输出结果是</p></p>
- 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); } } 对于以上代码,其运行结果是
- <p>请先阅读下面的代码。</p><p>public class Test03 {</p><p> public static void main(String args[]) {</p><p> int x = 4, j = 0;</p><p> switch (x) {</p><p> case 1:</p><p> j++;</p><p> case 2:</p><p> j++;</p><p> case 3:</p><p> j++;</p><p> case 4:</p><p> j++;</p><p> case 5:</p><p> j++;</p><p> default:</p><p> j++;</p><p> }</p><p> System.out.println(j);</p><p> }</p><p>}</p><p> 上面一段程序运行结束时,变量j的值为下列哪一项?</p> A: 4 B: 2 C: 1 D: 3
- 对于一下程序,其运行结果为</p></p>classBase{</p></p>publicBase(){</p></p>System.out.print("C");</p></p>}</p></p>}</p></p>classBase2extendsBase{</p></p>publicBase2(){</p></p>System.out.print("B");</p></p>}</p></p>}</p></p>publicclassTestDemoextendsBase2{</p></p>intm=1;</p></p>publicTestDemo(){</p></p>System.out.println("A");</p></p>}</p></p>publicstaticvoidmain(Stringargs[]){</p></p>TestDemot=newTestDemo();</p></p>}</p></p>}</p></p>
- 关于以下程序,其编译和运行结果为()</p></p>classBase{</p></p>publicBase(){</p></p>System.out.print('B');</p></p>}</p></p>}</p></p>publicclassTestDemoextendsBase{</p></p>intm=1;</p></p>publicTestDemo(){</p></p>System.out.println('A');</p></p>}</p></p>publicstaticvoidmain(Stringargs[]){</p></p>TestDemot=newTestDemo();</p></p>}</p></p>}</p></p>