练习11:将AllTheColorsOfTheRainbow这个示例改写成一个程序,然后编译、运行。
该示例在本书第36页
示例为:
class AllTheColorOfTheRainbow
{
int anIntegerRerRepresentingColors;
void changeTheHueOfTheColor(int newHue)
{
//...
}
}
改写为:
class AllTheColorsOfTheRainbow
{
int anIntegerRerRepresentingColors=9;
int Hue=6;
void changeTheHueOfTheColor(int newHue)
{
this.Hue=anIntegerRerRepresentingColors;
}
}
public class Main
{
public static void main(String[] args) {
AllTheColorsOfTheRainbow atcotr = new AllTheColorsOfTheRainbow();
System.out.println(atcotr.Hue);
atcotr.changeTheHueOfTheColor(atcotr.Hue);
System.out.println(atcotr.Hue);
}
}