==號并不能判斷兩個引用的值,系統會報錯
public?class?Dog?{
?????????int?age=18;
????? }
?????
public?class?Dog1?{??
?????????int?age=18;?
????????}
????????
?public?class?Init?{
?public?static?void?main(String[]?args)?{
? Dog?o=new?Dog();
? Dog1?o1=new?Dog1();
? if(o==o1){
? System.out.println("相同");
? }
? else{
? System.out.println("不相同");
? }
?????}
?}
2019-02-25
因為你是定義了兩個類,你比對的還是兩個類,而教程中的同一個類,只不過創建了兩次,所以才進行的比對
2019-02-26
你需要創建同一個類型的對象,像這樣
Dog?o=new?Dog();???????????????Dog o1=new?Dog();然后對對象的屬性值進行對比