ex2.java

来自「JAVA 编程思想 第四版 课后习题答案 代码全!」· Java 代码 · 共 26 行

JAVA
26
字号
// interfaces/Ex2.java
// TIJ4 Chapter Interfaces, Exercise 2, page 315
// Create a class as abstract without including any abstract methods, and verify
// that you cannot create any instances of that class.

abstract class Nogo1 {
	Nogo1() { System.out.println("Nogo1()"); }
}

abstract class Nogo2 {}

class Go1 extends Nogo1 {
	Go1() { System.out.println("Go1()"); }
}

public class Ex2 {
	public static void main(String[] args) {
		// Nogo1 and Nogo2 cannot be instantiated:
		// Nogo1 ng1 = new Nogo1();
		// Nogo2 ng2 = new Nogo2();
		// But Nogo1() constructor called during instatiation of child:
		Go1 g1 = new Go1();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?