?? ex4.java
字號:
// interfaces/Ex4.java
// TIJ4 Chapter Interfaces, Exercise 4, page 315
/* Create an abstract class with no methods. Derive a class and add a method.
* Create a static method that takes a reference to the base class, downcasts
* it to the derived class, and calls the method. In main(), demonstrate that it
* works. Now put the abstract declaration for the method in the base class, thus
* eliminating the need for the downcast.
*/
import static org.greggordon.tools.Print.*;
abstract class Dad {
}
class Son extends Dad {
protected void print() { println("Son"); }
}
abstract class SecondDad {
abstract protected void print();
}
class SecondSon extends SecondDad {
protected void print() { println("SecondSon"); }
}
public class Ex4 {
public static void testPrint(Dad d) {
((Son)d).print();
}
public static void secondTestPrint(SecondDad sd) {
sd.print();
}
public static void main(String[] args) {
Son s = new Son();
Ex4.testPrint(s);
SecondSon ss = new SecondSon();
Ex4.secondTestPrint(ss);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -