這個為什么會報錯?
這個為什么會報錯?創建了一個父類Celphone,一個子類phone。在創建對象時,只有父類能創建,子類創建的時候就報錯了,請問這是什么意思???
package equal;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Celphone phone1=new Celphone();
phone phone=new Phone();
phone1.Screen=6;
phone1.Cpu=5;
phone1.Mum=4;
Celphone phone2=new Celphone();
phone2.Screen=6;
phone2.Cpu=5;
phone2.Mum=4;
if(phone1.equals(phone2)){
System.out.println("兩者相同");
}else{
System.out.println("兩種不同");
}
}
2016-09-27
你這段代碼不合理,
package equal;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Celphone phone1=new Celphone();
phone phone=new Phone();
phone1.Screen=6;
phone1.Cpu=5;
phone1.Mum=4;
Celphone phone2=new Celphone();
phone2.Screen=6;
phone2.Cpu=5;
phone2.Mum=4;
if(phone1.equals(phone2)){
System.out.println("兩者相同");
}else{
System.out.println("兩種不同");
}
}
在我表明的下劃線那里,你應該改成Phone phone = new Phone();
2016-09-27
第五行phone phone=new Phone();應該寫成Phone phone = new Phone();
類類型規范是要求大寫首字母的,這個屬于筆誤。