Think in Java chapter of the second study

Think in Java author of this book introduces Java-related knowledge in words easy to understand, and finally there will be exercises in this chapter to learn about the content of the chapter. Raiders these exercises gives me a sense of accomplishment, but also an affirmation of their own learning content.

For example, some comment statement following the code of the printout, makes it easy to understand:

public class Practice06 {
static class StaticTest {
static int i = 48;
}
static class Incrementable {
static void increment() {
StaticTest.i++;
}
}
public static class ITest {
public static void main(String[] args) {
System.out.println("StaticTest.i="+StaticTest.i);
StaticTest st1 = new StaticTest();
StaticTest st2 = new StaticTest();
System.out.println("st1.i="+st1.i);
System.out.println("st2.i="+st2.i);
Incrementable it = new Incrementable();
it.increment();
System.out.println ( "it.increment () method gets called:");
System.out.println ( "st1.i =" + st1.i);
System.out.println ( "= st2.i" st2.i +);
; () Incrementable.increment
"after Incrementable.increment (method is called System.out.println ():");
System.out.println ( "st1.i =" + st1.i);
System.out.println ( "st2.i =" + st2.i);
}
}
}
================== parting line ========= ==========
public class Practice10 {
public static void main(String[] args) {
AllTheColorsOfTheRainbow act = new AllTheColorsOfTheRainbow();
System.out.println("act.anIntegerRepresentingColors = "+act.anIntegerRepresentingColors);
act.changeColor(7);
act.changeTheHueOfTheColor(77);
System.out.println("颜色改变后,act.anIntegerRepresentingColors = "+act.anIntegerRepresentingColors);
System.out.println("act.hue = "+act.hue);
}
}
class AllTheColorsOfTheRainbow {
int anIntegerRepresentingColors = 0;//用基本类型来代表颜色
int hue = 0;
void changeTheHueOfTheColor (int newHue) {
hue = newHue;
}
Int changeColor (int newColor) {
return anIntegerRepresentingColors = newColor;
}
}
Most of the exercises in this book are the chapters appeared in over the code morphing, step by step, write your own code to run successfully after feeling their efforts were not in vain, no knock day "BUG", 233333

Guess you like

Origin www.cnblogs.com/yyslif/p/11122471.html