?? ex10.java
字號(hào):
// polymorphism/Ex10.java
// TIJ4 Chapter Polymorphism, Exercise 10, page 290
/* Create a base class with two methods. In the first method, call the second
* method. Inherit a class and override the second method. Create an object of
* the derived class, upcast it to the base type, and call the first method.
* Explain what happens.
*/
class A {
protected void f() {
System.out.println("A.f()");
this.g();
}
protected void g() {
System.out.println("A.g()");
}
}
class B extends A {
@Override protected void g() {
System.out.println("B.g()");
}
}
public class Ex10 {
public static void main(String[] args) {
B b = new B();
// automatic upgrade to base-class to call base-class method A.f()
// which,by polymorphism, will call the derived-class method B.g():
b.f();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -