constructordemo.java

来自「《Java语言程序设计》源代码 很好的JAVA入门的好的代码」· Java 代码 · 共 30 行

JAVA
30
字号
public class ConstructorDemo{
	int width;
	int length;
	int height;
	public ConstructorDemo(int a){
		width=a;length=a;height=a;
	}
	public ConstructorDemo(int a,int b){
	   width=a;length=a;height=b;
	}
	public ConstructorDemo(int a,int b,int c){
		width=a;length=b;height=c;
	}
	public int volume(){
		return width*length*height;
	}
	public void display(){
		System.out.println("The box volume is : "+this.volume());
	}
	public static void main(String args[]){
	  ConstructorDemo c1,c2,c3;
	  c1=new ConstructorDemo(5);
	  c1.display();
	  c2=new ConstructorDemo(5,6);
	  c2.display();
	  c3=new ConstructorDemo(5,6,7);
	  c3.display();
	}
}

⌨️ 快捷键说明

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