Java代码
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.compare();
t.compare2();
}
public void compare()
{
//1
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
Integer i3 = i1;
System.out.println(i1 == i2);
System.out.println(i1 == i3);
System.out.println(i1.equals(i2));
System.out.println();
//2
Boolean b1 = new Boolean(false);
Boolean b2 = new Boolean(false);
Boolean b3 = b1;
System.out.println(b1 == b2);
System.out.println(b1 == b3);
System.out.println(b1.equals(b2));
System.out.println();
//3
int[] a1 = new int[3];
int[] a2 = new int[3];
int[] a3 = a1;
System.out.println(a1 == a2);
System.out.println(a1 == a3);
System.out.println(a1.equals(a2));
System.out.println();
}
public void compare2()
{
TestC tc = new TestC();
TestB tb = new TestB();
TestA ta = new TestA();
System.out.println(tc == tb);
System.out.println(tc == ta);
ta = tb;
System.out.println(ta == tb);
ta = tc;
System.out.println(ta == tc);
ta = new TestC();
System.out.println(ta == tc);
}
}
class TestC extends TestB
{
}
class TestB extends TestA
{
}
class TestA
{
}
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.compare();
t.compare2();
}
public void compare()
{
//1
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
Integer i3 = i1;
System.out.println(i1 == i2);
System.out.println(i1 == i3);
System.out.println(i1.equals(i2));
System.out.println();
//2
Boolean b1 = new Boolean(false);
Boolean b2 = new Boolean(false);
Boolean b3 = b1;
System.out.println(b1 == b2);
System.out.println(b1 == b3);
System.out.println(b1.equals(b2));
System.out.println();
//3
int[] a1 = new int[3];
int[] a2 = new int[3];
int[] a3 = a1;
System.out.println(a1 == a2);
System.out.println(a1 == a3);
System.out.println(a1.equals(a2));
System.out.println();
}
public void compare2()
{
TestC tc = new TestC();
TestB tb = new TestB();
TestA ta = new TestA();
System.out.println(tc == tb);
System.out.println(tc == ta);
ta = tb;
System.out.println(ta == tb);
ta = tc;
System.out.println(ta == tc);
ta = new TestC();
System.out.println(ta == tc);
}
}
class TestC extends TestB
{
}
class TestB extends TestA
{
}
class TestA
{
}
输出为:
Java代码
false
true
true
false
true
true
false
true
false
false
false
true
true
false
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.compare();
t.compare2();
}
public void compare()
{
//1
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
Integer i3 = i1;
System.out.println(i1 == i2);
System.out.println(i1 == i3);
System.out.println(i1.equals(i2));
System.out.println();
//2
Boolean b1 = new Boolean(false);
Boolean b2 = new Boolean(false);
Boolean b3 = b1;
System.out.println(b1 == b2);
System.out.println(b1 == b3);
System.out.println(b1.equals(b2));
System.out.println();
//3
int[] a1 = new int[3];
int[] a2 = new int[3];
int[] a3 = a1;
System.out.println(a1 == a2);
System.out.println(a1 == a3);
System.out.println(a1.equals(a2));
System.out.println();
}
public void compare2()
{
TestC tc = new TestC();
TestB tb = new TestB();
TestA ta = new TestA();
System.out.println(tc == tb);
System.out.println(tc == ta);
ta = tb;
System.out.println(ta == tb);
ta = tc;
System.out.println(ta == tc);
ta = new TestC();
System.out.println(ta == tc);
}
}
class TestC extends TestB
{
}
class TestB extends TestA
{
}
class TestA
{
}
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.compare();
t.compare2();
}
public void compare()
{
//1
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
Integer i3 = i1;
System.out.println(i1 == i2);
System.out.println(i1 == i3);
System.out.println(i1.equals(i2));
System.out.println();
//2
Boolean b1 = new Boolean(false);
Boolean b2 = new Boolean(false);
Boolean b3 = b1;
System.out.println(b1 == b2);
System.out.println(b1 == b3);
System.out.println(b1.equals(b2));
System.out.println();
//3
int[] a1 = new int[3];
int[] a2 = new int[3];
int[] a3 = a1;
System.out.println(a1 == a2);
System.out.println(a1 == a3);
System.out.println(a1.equals(a2));
System.out.println();
}
public void compare2()
{
TestC tc = new TestC();
TestB tb = new TestB();
TestA ta = new TestA();
System.out.println(tc == tb);
System.out.println(tc == ta);
ta = tb;
System.out.println(ta == tb);
ta = tc;
System.out.println(ta == tc);
ta = new TestC();
System.out.println(ta == tc);
}
}
class TestC extends TestB
{
}
class TestB extends TestA
{
}
class TestA
{
}
输出为:
Java代码
false
true
true
false
true
true
false
true
false
false
false
true
true
false