我是靠谱客的博主 殷勤楼房,这篇文章主要介绍java 继承与多态练习题目,现在分享给大家,希望可以做个参考。

//请写出以下程序的运行结果....
public class A {
public String show(D obj) {
return ("A and D");
}


public String show(A obj) {
return ("A and A");
}


public static void main(String[] args) {
A a1 = new A();
A a2 = new B();
B b = new B();
C c = new C();
D d = new D();
System.out.println(a1.show(b)); // ①
System.out.println(a1.show(c)); // ②
System.out.println(a1.show(d));//  ③
System.out.println(a2.show(b)); // ④
System.out.println(a2.show(c));//  ⑤
System.out.println(a2.show(d));//  ⑥
System.out.println(b.show(b)); //  ⑦
System.out.println(b.show(c)); //  ⑧
System.out.println(b.show(d)); //  ⑨
}
}


class B extends A {
public String show(B obj) {
return ("B and B");
}


public String show(A obj) {
return ("B and A");
}
}


class C extends B {
}


class D extends B {

}





ans:

A and A
A and A
A and D
B and A
B and A
A and D
B and B
B and B
A and D

最后

以上就是殷勤楼房最近收集整理的关于java 继承与多态练习题目的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部