This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Private Variable in an Enum

 
Mehdi Ben Larbi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,i am having some trouble to understand question 7 in Chapter 3 :



Question :

Which are true? (Choose all that apply.)

A. The output could contain 30
B. The output could contain @bf73fa
C. The output could contain DIAMONDS
D. Compilation fails due to an error on line 6
E. Compilation fails due to an error on line 7
F. Compilation fails due to an error on line 8
G. Compilation fails due to an error on line 9
H. Compilation fails due to an error within lines 12 to 14

The answer is :

A. The output could contain 30
B. The output could contain @bf73fa

I have two questions :

-How can the static main access the Enum ? Isn't it supposed to create a new Bridge first to access non-static variables or methods ?
-How can we access the points variable while it's private in the Enum ?

Thank you.

EDIT : getBidValue isn't defined,there is an error in the book's code.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your coding, there are some error. Where is getBidValue() method?

nested enums are static members of the enclosing class. And enum constants are also static members implicitly. so no need to instantiate Bridge class. For your final question, try declare your enum out of the class Bridge and run again!
 
Mehdi Ben Larbi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:Check your coding, there are some error. Where is getBidValue() method?

nested enums are static members of the enclosing class. And enum constants are also static members implicitly. so no need to instantiate Bridge class. For your final question, try declare your enum out of the class Bridge and run again!


You are right,the method is getValue(),there is an error in the book.
Thanks a lot for your answer,i didn't know that nested enums were static members,that explains everything.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic