public static void main(String[] args) {
int a = 1; int b = 2;
System.out.println(a);
System.out.println(b);
change(a, b);
System.out.println(a);
System.out.println(b);
}
public static void change(int a, int b) {
a = a + b; b = b + a;
}
分析下列程序代码,猜想下输出结果。
package Polymorphic;
//爷爷类
class Ye {
public String show(Sun obj) {
return ("Ye and Sun");
}
public String show(Ye obj) {
return ("Ye and Ye");
}
}
//爸爸类
class Fu extends Ye {
public String show(Fu obj) {
return ("Fu and Fu");
}
public String show(Ye obj) {
return ("Fu and Ye");
}
}
//儿子类
class Zi extends Fu {
}
//孙子类
class Sun extends Fu {
}
public class PolymorphicTest {
public static void main(String[] args) {
Ye y = new Ye();
Ye y2 = new Fu(); //向上
Fu f = new Fu();
Zi z = new Zi();
Sun s = new Sun();
第一题 Ye and Ye
第二题 Ye and Ye
第三题 Ye and Sun
第四题 Fu and Ye
第五题 Fu and Ye
第六题 Ye and Sun
第七题 Fu and Fu
第八题 Fu and Fu
第九题 Ye and Sun
分析的话就涉及到太多知识点了,比如多态的金典向上向下转型,这都是必备的重点基础的基础,建议参考这篇文章【蓝色字体,点击进入】