KiMoGiGi 技术文集

不在乎选择什么,而在乎坚持多久……

IT博客 首页 联系 聚合 管理
  185 Posts :: 14 Stories :: 48 Comments :: 0 Trackbacks

写出以下代码的输出结果

class A{
 public String f(D obj){return ("A and D");}
 public String f(A obj){return ("A and A");}
}
class B extends A{
 public String f(B obj){return ("B and B");}
 public String f(A obj){return ("B and A");}
}
class C extends B{}
class D extends B{}

class test{
 A a1 = new A();
 A a2 = new B();
 B b = new B();
 C c = new C();
 D d = new D();
 System.out.println(a1.f(b));   A and A
 System.out.println(a1.f(c));   A and A
 System.out.println(a1.f(d));   A and D
 System.out.println(a2.f(b));   B and A
 System.out.println(a2.f(c));   B and A
 System.out.println(a2.f(d));   A and D
 System.out.println(b.f(b));    B and B
 System.out.println(b.f(c));    B and B
 System.out.println(b.f(d));   A and D
}

posted on 2006-11-19 15:47 KiMoGiGi 阅读(158) 评论(0)  编辑 收藏 引用 所属分类: C# / Winforms
只有注册用户登录后才能发表评论。