superdemo.java

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

JAVA
88
字号
//using super class to call a super class
class Box
{
	private double width;
	private double height;
	private double depth;

	Box(Box ob)
	{
		width = ob.width;
		height = ob.height;
		depth = ob.depth;
	}

	Box(double w, double h, double d)
	{
		width = w;
		height = h;
		depth = d;
	}

	Box()
	{
		width = height = depth = -1;
	}

	Box(double len)
	{
		width = height = depth = len;
	}

	double volume()
	{
		return width*height*depth;
	}
}

class boxWeight extends Box
{
	double weight;

	boxWeight(boxWeight ob)
	{
		super(ob);
		weight = ob.weight;
	}

	boxWeight(double w, double h, double d, double wh)
	{
		super(w,h,d);
		weight = wh;
	}

	boxWeight()
	{
		super();
		weight = -1;
	}

	boxWeight(double len, double wh)
	{
		super(len);
		weight = wh;	
	}
/*	double volume()
	{
		return super.volume()*weight;
	}
*/
}

class superDemo
{
	public static void main(String args[])
	{
		boxWeight mybox1 = new boxWeight();
		boxWeight mybox2 = new boxWeight(1,2,3,4);
		boxWeight mycube = new boxWeight(3,4);
		double vol;

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

⌨️ 快捷键说明

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