Monday, October 26, 2009

Pg. 367 Exercise 10

In the PennyJar.java 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 PennyJarDriver.java 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 PennyJar.java program, but not from the PennyJarDriver.java, then the program executes normally.

No comments:

Post a Comment