c.java

来自「Thinking in Java第四版 课后习题的源码」· Java 代码 · 共 21 行

JAVA
21
字号
// reusing/Ex5/C.java
// TIJ4 Chapter Reusing, Exercise 5, page 245
/* Create two classes, A and B, with default constructors (empty argument
* lists) that announce themselves. Inherit a new class called C from A, and
* create a member of class B inside C. Do not create a constructor for C. Create
* an object of class C and observe the resluts. 
*/
 
import static org.greggordon.tools.Print.*;

class A { A(){ println("A()");} }

class B extends A { B(){ println("B()");} }

class C extends A { 
	B b = new B(); // will then construct another A and then a B
	public static void main(String[] args) {
		C c = new C(); // will construct an A first
	}
}

⌨️ 快捷键说明

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