伙计....我有一个儿童班GateNot
,其延伸Gate
。我不确定如何填写GateNot
的构造函数,因为我没有在子类中给出任何实例变量。方法是什么?
public class GateNot extends Gate {
public GateNot(Wire input, Wire output)
{
super()
}
}
import java.util.*;
public abstract class Gate implements Logic {
private List<Wire> inputs;
private Wire output;
private String name;
public Gate(String name, List<Wire> ins, Wire out)
{
this.name = name;
this.output = out;
if(ins.size() == 0 || ins.isEmpty())
throw new ExceptionLogicParameters(false, 1, 0);
else
this.inputs = ins;
}
@Override
public void feed(List<Signal> inSigs)
{
if(inSigs.size() != inputs.size())
throw new ExceptionLogicParameters(false, inputs.size(), inSigs.size());
else
{
for(int i = 0; i < inSigs.size(); i++)
{
inputs.get(i).setSignal(inSigs.get(i));
}
}
}
@Override
public void feed(String name)
{
if(!(this.name.equals(name)))
throw new ExceptionLogicMalformedSignal(name.charAt(0), "Invalid logic input");
else
{
Signal signalValue = Signal.fromString(name.charAt(0));
}
}
@Override
public List<Signal> read()
{
List<Signal> signals = new ArrayList<>();
signals.add(output.getSignal());
return signals;
}
@Override
public String toString()
{
return this.name+"( " + inputs.toString() + " | " + output.toString() + " )";
}
@Override
public boolean equals(Object other)
{
if(other instanceof Gate)
{
Gate someGate = (Gate)other;
return (this.inputs == someGate.inputs) && (this.output.equals(someGate.output)
&& (this.name.equals(someGate.name)));
}
else
return false;
}
public List<Wire>getInputs()
{
return this.inputs;
}
public Wire getOutput()
{
return this.output;
}
public String getName()
{
return this.name;
}
public void setInputs(List<Wire> inputs)
{
this.inputs = inputs;
}
public void setOutput(Wire output)
{
this.output = output;
}
public void setName(String name)
{
this.name = name;
}
}
答案 0 :(得分:4)
你必须调用超类的构造函数。
根据超类的构造函数的参数类型和名称,我说这就是你需要的:
public GateNot(Wire input, Wire output)
{
super("Not", Arrays.asList(new Wire[]{input}), output);
}