java编写一个light类,包含两个成员变量,两个构造器方法,三个成员方法
时间: 2024-05-20 17:16:27 浏览: 101
java 一个灯的程序
4星 · 用户满意度95%
public class Light {
private boolean isOn;
private String color;
public Light() {
this(false, "white");
}
public Light(boolean isOn, String color) {
this.isOn = isOn;
this.color = color;
}
public void turnOn() {
this.isOn = true;
}
public void turnOff() {
this.isOn = false;
}
public void setColor(String color) {
this.color = color;
}
public boolean isOn() {
return isOn;
}
public String getColor() {
return color;
}
}
阅读全文