File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Private Variable in an Enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Private Variable in an Enum" Watch "Private Variable in an Enum" New topic
Author

Private Variable in an Enum

Mehdi Ben Larbi
Ranch Hand

Joined: Aug 17, 2010
Posts: 70
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.


SCJP 93 % ,preparing for SCWCD
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Mehdi Ben Larbi
Ranch Hand

Joined: Aug 17, 2010
Posts: 70
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Private Variable in an Enum
 
Similar Threads
Discussing errata for K&B, SCJP 6
K&B doubt(unofficial errata) Moderators,Please keep this thread on the top so all to see and add
Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7
What is the output for this Class
Miscellaneous Doubts