⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 obj_inheritence.java

📁 JAVA程序设计课程中各章节的程序实例。
💻 JAVA
字号:
//Allocation of an object to inheritise another
class Box
{
	double height;
	double width;
	double depth;

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

	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(double len)
	{
		width = height = depth = len;
	}

	double volume()
	{
		return width*height*depth;
	}
}
class Obj_inheritence
{
	public static void main(String args[])
	{
		Box mybox1 = new Box(10,20,15);
		Box mybox2 = new Box();
		Box mycube = new Box(7.7);
		Box myclone = new Box(mybox1);

		double vol;

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

		vol = mybox2.volume();
		System.out.println(vol);

		vol = mycube.volume();
		System.out.println(vol);

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

⌨️ 快捷键说明

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