|
Java学习者论坛
请看:
public class Light {
private int watts;
private boolean indicator;
public Light(int watts){
this.watts=watts;
}
public Light(int watts,boolean indicator){
this.watts=watts;
this.indicator=indicator;
}
public void switchOn(){
this.indicator=true;
}
public void switchOff(){
this.indicator=false;
}
public void printInfo(){
System.out.println("watts:"this.watts"indicator:"+this.indicator);
}
}
class TubeLight extends Light{
private int tubeLength;
private String color;
private int watts;
private boolean indicator;
public TubeLight(int watts,int tubeLength,String color){
super(watts);
this.watts=watts;
this.color=color;
this.tubeLength=tubeLength;
}
public void printInfo(){
System.out.println("watts:"this.watts" indicator:"this.indicator" tubeLength:"this.tubeLength" color:"+this.color);
}
}
请问在以上的父类Light和子类TubeLight中,为什么子类TubeLight的构造方法public TubeLight(int watts,int tubeLength,String color)一定要调用super(watts),否则报错:
TubeLight.java:6: 找不到符号
符号: 构造函数 Light()
位置: 类 Light
public TubeLight(int watts,int tubeLength,String color){
欢迎来到Java学习者论坛,转载请注明地址:http://www.javaxxz.com. |
|