constructor.java

来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 32 行

JAVA
32
字号
//Constructor in a class
class Box
{
	double width;
	double height;
	double depth;

	Box()
	{
		System.out.println("Constructing a box");
		width = 10;
		height = 15;
		depth = 5;
	}
	
	double volume()
	{
		return width*height*depth;
	}
}

class Constructor
{
	public static void main(String args[])
	{
		Box mybox1 = new Box();
		double vol;

		vol = mybox1.volume();
		System.out.println(vol);
	}
}

⌨️ 快捷键说明

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