object class是所有類別的superclass
String str1 = "hello";
//直接將hello的記憶體位置給str1,str1的位置=hello的位置。
String str2= new String("hello");
//先分配一個記憶體空間給str2,接著,內容值是存放
public class TestEquals
{
public static void main(String[] args)
{
MyDate date1 = new MyDate(14, 3, 1976);
MyDate date2 = new MyDate(14, 3, 1976);
if ( date1 == date2 ) {
System.out.println("date1 is identical to date2");
} else {
System.out.println("date1 is not identical to date2");
}
if ( date1.equals(date2) ) {
System.out.println("date1 is equal to date2");
} else {
System.out.println("date1 is not equal to date2");
}
System.out.println("set date2 = date1;");
date2 = date1;
if ( date1 == date2 ) {
System.out.println("date1 is identical to date2");
} else {
System.out.println("date1 is not identical to date2");
}
}
}
沒有留言:
張貼留言