ex3.java
来自「Thinking in Java 习题答案源码打包」· Java 代码 · 共 46 行
JAVA
46 行
package Interfaces;
// interfaces/Ex3.java
// TIJ4 Chapter Interfaces, Exercise 3, page 315
/* Create a base class with an abstract print() method that is overridden in a
* derived class. The overridden version of the method prints the value of an int
* variable defined in the derived class. At the point of definition of this
* variable, give it a nonzero value. In the base-class constructor, call this
* method. In main(), create an object of the drived type, and then call its
* print() method. Explain the results.
*/
abstract class Dad
{
protected abstract void print();
Dad()
{
print();
}
}
class Son extends Dad
{
private int i = 1;
protected void print()
{
System.out.println( "Son.i = " + i );
}
}
public class Ex3
{
public static void main( String[] args )
{
Son s = new Son();
s.print();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?