public class Account {
String account;
double balance;
Account(String account, double balance) {
this.account = account;
this.balance = balance;
}
}
public class AccountTest {
public static void main(String[] args) {
Account a1 = new Account("Sandy", 1000);
Account a2 = new Account("Sandy", 1000);
System.out.println(a1.equals(a2));
}
}
當我執行它顯示「false」但對象包含變量中的相同數據時。爲什麼解釋。爲什麼使用equals()方法時兩個具有相同數據的對象不相等
但爲什麼是負面投票? – vineet