【发布时间】:2014-04-14 15:50:45
【问题描述】:
我不断收到此错误:boolean;发现:没有参数;原因:实际参数列表和形式参数列表的长度不同;
我知道为什么会这样,因为我的超类和子类中的构造函数不匹配......但如果可能的话我不想对它们进行更改,因为它会破坏我的其他类的其余部分,如果我这样做需要进行更改 我宁愿只更改 LowRights 类。有人能指出我正确的方向吗?
public class LowRights extends SecurityRights
{
private String name;
public LowRights(String n){
this.name = n;
boolean right = getRight(); // Added
setRight(false); // Added
}
public boolean setRight(boolean right){
return right;
}
public String getName(){
return name;
}
public static void main(String[] a){
LowRights s= new LowRights("Lisa");
System.out.print(s.getName() +" "+s.getSecret());
}
}
这是我的超级班:
public class SecurityRights
{
private boolean right;
private boolean canreadSecret;
String SECRET="the secret is 42";
public SecurityRights(boolean r)
{
r = right;
if (r) canreadSecret=true; else canreadSecret=false;
}
boolean getRight(){
return right;
}
boolean canReadSecret(){
return canreadSecret;
}
String getSecret(){
if (canreadSecret) return SECRET; else return "access denied";
}
}
【问题讨论】:
标签: java inheritance constructor