【发布时间】:2015-05-19 04:58:00
【问题描述】:
我在尝试初始化新对象时收到此错误消息。
Cannot instantiate the type Car
我的代码
Main.java
public class Main {
public static void main(String args[]){
Car car = new Car(4,4,COUNTRY.MALAYSIA, Locale.ENGLISH, "150.00"); //error here
}
}
汽车.java
public abstract class Car implements Automobile {
public int wheel;
public int door;
public COUNTRY country;
public Locale locale;
public String price;
public Car(int w, int d, COUNTRY c, Locale l, String p){
this.wheel = w;
this.door = d;
this.country = c;
this.locale = l;
this.price = p;
}
}
【问题讨论】:
-
你不能实例化一个抽象类。但是,您可以创建抽象类的子类并实例化它。
-
将
abstract关键字移至Car 类,因为抽象类无法实例化。
标签: java