您的位置:首页 > 编程语言 > Java开发

Java编程思想 第4版 练习题 / 第2章 一切都是对象 / 练习11

2010-04-17 02:33 411 查看
// TIJ4 第2章 一切都是对象, 练习 11, 第 90 页;
// 将AllTheColorsOfTheRainbow这个示例改写成一个程序,然后编译、运行。
class AllTheColorsOfTheRainbow{
int anIntegerPepresentingColors = 0;
int hue = 0;
void changTheHueOfTheColor(int newHue){
this.hue = newHue;
}
void changColor(int newColor){
this.anIntegerPepresentingColors = newColor;
}
}

public class RainbowColorTest{
public static void main(String[] args){
AllTheColorsOfTheRainbow aCR = new AllTheColorsOfTheRainbow();
System.out.println("aCR.anIntegerPepresentingColors = "+ aCR.anIntegerPepresentingColors);
System.out.println("aCR.hue = "+ aCR.hue);
aCR.changTheHueOfTheColor(75);
aCR.changColor(12);
System.out.println("通过aCR对象调用AllTheColorsOfTheRainbow类的方法");
System.out.println("aCR.anIntegerPepresentingColors = "+ aCR.anIntegerPepresentingColors);
System.out.println("aCR.hue = "+ aCR.hue);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: