⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex3.java

📁 Thinking in Java 习题答案源码打包
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -