![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
On page 376 of Thinking In Java, 2nd edition, Bruce Eckel gives an example of creating a "constructor" within an anonymous inner class using instance initialization. Now, I do understand what instance initialization is, and I do know what a field variable is, and I do readily concede that Bruce's example code Parcel9.java will not compile without instance initialization. But I do not understand why instance initialization *must* be used. Why is it that the compiler balks at the "if(cost > 100)" conditional, when, experimentally, I initialize the "cost" variable as a field variable with the value "Math.round(price)", and I do not include the instance-initializing brackets around the conditional? What's wrong with having a conditional that evaluates a field variable from within an anonymous inner class? I'm hoping someone will explain this example to me; I'm obviously missing something pretty basic!! Thanks in advance, and I will really appreciate any help people are kind enough to give me... -Andrew Replies:
|
Sponsored Links
|