這個(gè)為什么會(huì)報(bào)錯(cuò)?
這個(gè)為什么會(huì)報(bào)錯(cuò)?創(chuàng)建了一個(gè)父類Celphone,一個(gè)子類phone。在創(chuàng)建對(duì)象時(shí),只有父類能創(chuàng)建,子類創(chuàng)建的時(shí)候就報(bào)錯(cuò)了,請(qǐng)問這是什么意思???
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("兩種不同");
}
}
在我表明的下劃線那里,你應(yīng)該改成Phone phone = new Phone();
2016-09-27
第五行phone phone=new Phone();應(yīng)該寫成Phone phone = new Phone();
類類型規(guī)范是要求大寫首字母的,這個(gè)屬于筆誤。