我必須寫一個Resistor類。當電阻對象首次實例化時,其默認電阻爲1歐姆,其默認類型爲「電影」。這是我所有的如何在方法中使用setter和getters
public class Resistor{
private int resistance;
private int type;
public Resistor(int r) {
resistance = r;
}
public int getResistance() {
return resistance;
}
public double getType() {
return type;
}
}
你是什麼問題? –
如果'type'的默認值應該是'「film」',那麼「film」幾乎可以肯定是一個字符串而不是int。 – nhgrif
只需使用枚舉而不是int或String即可。但是,不確定這個問題到底是什麼。 – TastyLemons