刚开始学习Java,我怎样才能改变它以便它实际输出lamp1.printStates
,lamp2.printStates?
当我运行它时,它只是返回它构建成功,但没有别的。
package lamps;
public class Lamps {
public static void main(String[] args) {
class Lamp {
int on = 0;
int brightness = 0;
void changeOn(int newValue) {
on = newValue;
}
void changeBrightness(int newValue) {
brightness = newValue;
}
void printStates() {
System.out.println("On/Off:" + on +
" brightness:" + brightness);
}
}
class CreateLamps {
public void main(String[] args) {
Lamp lamp1 = new Lamp();
Lamp lamp2 = new Lamp();
lamp1.changeOn(1);
lamp1.changeBrightness(4);
lamp1.printStates();
lamp2.changeOn(1);
lamp2.changeBrightness(6);
lamp2.changeBrightness(4);
lamp2.changeOn(0);
lamp2.changeBrightness(0);
lamp2.printStates();
}
}
}
}