polyconstructors.java

来自「java编程思想的部分实现」· Java 代码 · 共 33 行

JAVA
33
字号
//:c07:PolyConstructors.java

abstract class Glyph
{
	abstract void draw();
	Glyph()
	{
		System.out.println("Glyph() before draw()");
		draw();
		System.out.println("Glyph() after draw()");
	}
}
class RoundGlyph extends Glyph
{
	int radius=1;
	RoundGlyph(int r)
	{
		System.out.println("RoundGlyph.RoundGlyph(),radius= "+radius);
		radius=r;
		System.out.println("RoundGlyph.RoundGlyph(),radius= "+radius);
	}
	void draw()
	{
		System.out.println("RoundGlyph.draw(),radius= "+radius);
	}
}
public class PolyConstructors
{
	public static void main(String [] args)
	{
		new RoundGlyph(5);
	}
}

⌨️ 快捷键说明

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