• 2021-04-14
    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); } } 对于以上代码,其运行结果是
  • Manager male Employee female

    举一反三

    内容

    • 0

      对于一下程序,其运行结果为 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(); } }

    • 1

      编译并运行下面的程序,结果是 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"); } }

    • 2

      有如下类的定义。class A{ public void show() { show2(); } public void show2() { System.out.print("我"); }}class B extends A{ public void show2(){ System.out.print("爱"); }}class C extends B{ public void show() { super.show(); } public void show2() { System.out.print("你"); }}public class Test4 { public static void main(String[] args) { A a=new B(); a.show(); B b=new C(); b.show(); }} A: 我爱你 B: 爱你 C: 我爱 D: 我你

    • 3

      请写出以下程序运行结果: public class Main { public Main() { System.out.print("main "); } public Main(String s) { this(); System.out.print("main with "+s); } public static void main(String[] args) { Main main = new Main("wow"); } }

    • 4

      下列程序的运行结果是()。 public class Test public static void main ( String [ ] args ) int count = 0 for( int i = 1 i < 5 i = 2) for( int j = 1 j< = 10 j = 3) count System .out .print (count ) _