package jiCheng_duoTai;
public class DuoTaiLiJieLianXiTi {
public static void main(String[] args) {
AAA a1 = new AAA();
AAA a2 = new BBB();
BBB b = new BBB();
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));
}
}
//先在本类的方法里面找,若没有再找父类(参数相同),如果还没有找到,就再找本类(参数的父类),如果还没有再去父类找
//1. this.m(o);2. super.m(o);3.this.m(super(o));4. super.m(super(O))
class AAA{
public String show(D obj) {
return ("A and D");
}
public String show(AAA obj) {//obj=b;
return ("A and A");
}
}
class BBB extends AAA {
public String show(BBB obj) {
return ("B and B");
}
public String show(AAA obj) {
return ("B and A");
}
}
class C extends BBB {
}
class D extends BBB {
}
现在来逐步分解,看每个过程的变化状态
状态一:package jiCheng_duoTai;
public class DuoTaiLiJieLianXiTi {
public static void main(String[] args) {
AAA a1 = new AAA();
AAA a2 = new BBB();
BBB b = new BBB();
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));
}
}
class AAA{
public String show(D obj) {
return ("A and D");
}
public String show(AAA obj) {//obj=b;
return ("A and A");
}
}
class BBB extends AAA {
public String show(BBB obj) {
return ("B and B");
}
public String show(AAA obj) {
return ("B and A");
}
}
class C extends BBB {
}
class D extends BBB {
}
public class DuoTaiLiJieLianXiTi {
public static void main(String[] args) {
AAA a1 = new AAA();
AAA a2 = new BBB();
BBB b = new BBB();
C c = new C();
D d = new D();
System.out.println(a2.show(b));
System.out.println(a2.show(c));
System.out.println(a2.show(d));
}
}
class AAA{
public String show(D obj) {
return ("A and D");
}
public String show(AAA obj) {//obj=b;
return ("A and A");
}
}
class BBB extends AAA {
public String show(BBB obj) {
return ("B and B");
}
public String show(AAA obj) {
return ("B and A");
}
}
class C extends BBB {
}
class D extends BBB {
}
public class DuoTaiLiJieLianXiTi {
public static void main(String[] args) {
AAA a1 = new AAA();
AAA a2 = new BBB();
BBB b = new BBB();
C c = new C();
D d = new D();
System.out.println(b.show(b));
System.out.println(b.show(c));
System.out.println(b.show(d));
}
}
class AAA{
public String show(D obj) {
return ("A and D");
}
public String show(AAA obj) {//obj=b;
return ("A and A");
}
}
class BBB extends AAA {
public String show(BBB obj) {
return ("B and B");
}
public String show(AAA obj) {
return ("B and A");
}
}
class C extends BBB {
}
class D extends BBB {
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |