答案:错误。
众所周知,被abstract修饰的类是抽象类,抽象类不能被实例化,但是可以被继承,也可以继承。
那么根据代码:
public class Test1{
public static void main(String[] args) {
Car car=new Car(1); //异常:Cannot instantiate the type Car 不能实例化一个Car
car.color();
}
}
abstract class Car //抽象类
{
int length;
Car() //抽象类的无参构造
{
}
Car(int length) //抽象类的带参构造
{
this.length=length;
}
public void color()
{
System.out.print("I have color!");
}
}
在书中有明确说明:抽象类的构造方法定义为protected,因为他只能被子类使用,即用super(paraments);
参考文献:Java语言程序设计(第十版)P426页