Monday, October 26, 2009

Pg. 367 Exercise 10

In the program it is legal to remove the PennyJar. from the "PennyJar.allPennies++;" and "if(PennyJar.allPennies >= PennyJar.GOAL)" because the allPennies variable is class variable, and the GOAL variable is a constant variable.

However, in the program it is illegal to remove the PennyJar. from the "System.out.println(PennyJar.getAllPennies());" because getAllPennies() is a method declared in the PennyJar class. Without the PennyJar. in the statement the compiler cannot find the method.

If PennyJar. is omitted from the program, but not from the, then the program executes normally.

No comments:

Post a Comment