1.封装、继承、多态是oop的三个基本特征
2.多态通过分离做什么和怎么做来将接口和实现分离开。
3.方法调用的优先级从高到低:this.show(O) > super.show(O) > this.show((super)O) > super.show((super)O)
4.只有非private方法才能被覆盖,在导出类中,对于基类的private方法,最好采用不同的名字。
5.在网上找到的一个习题;
有如下类的定义:
class A ...{
public String show(D obj)...{
return ("A and D");
}
public String show(A obj)...{
return ("A and A");
}
}
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...{}
问下边的输出结果是多少:
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)); ⑨
答案依次是:
① 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
6.发杂对象的构造器的:
a)调用基类的构造器,并且不断的递归下去
b)按声明顺序调用成员的初始化方法
c)调用导出类构造器的主体
7.销毁顺序相反
8.向下转型异常的时候会抛出“classCastException”