testequality.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 31 行

JAVA
31
字号
public class TestEquality
{
	static void main(String[] args) throws Exception
	{
		VeryBasicBox box1 = new VeryBasicBox(4, 5, 6);
		VeryBasicBox box2 = new VeryBasicBox(2, 3, 4);
		System.out.println("The volume of box1 is " + box1.volume());
		System.out.println("The volume of box1 is " + box2.volume());
		
		if (box1.equals(box2))
			System.out.println("box1 and box2 have equal length, width and height.");
		else
			System.out.println("box1 and box2 do not have equal length, width and height.");
			
		if(box1 == box2)
			System.out.println("box1 and box2 are the same object");
		else 
			System.out.println("box1 and box2 are not the same object");
			
		VeryBasicBox box3 = new VeryBasicBox(2, 3, 4);
		if (box2.equals(box3))
			System.out.println("box2 and box3 have equal length, width and height. ");
		else
			System.out.println("box2 and box3 do not have equal length, width and height.");
		if (box2.equals(box2))
			System.out.println("box2 equals box2");
		else
			System.out.println("box2 does not equal box2");
	}
}

⌨️ 快捷键说明

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