*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Chapter 1 Question 8 Kathy & Bates book. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Chapter 1 Question 8 Kathy & Bates book." Watch "Chapter 1 Question 8 Kathy & Bates book." New topic
Author

Chapter 1 Question 8 Kathy & Bates book.

Adil Fulara
Greenhorn

Joined: Oct 21, 2007
Posts: 8
I had a doubt in the following question.




I answered F but the correct answer is A.

The reason i chose F was because i thought enum variables are private and cannot be accessed directly.
Since no access modifier was specified for 'sound' variable, i thought line 9 would complain that the instance variable is not visible.

Could someone please explain why my line of reasoning is wrong. Are instance variables of enums public by default?

Thank you
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Adil.
The reason i chose F was because i thought enum variables are private and cannot be accessed directly.

Here variable 'sound' has default scope.
Adil Fulara
Greenhorn

Joined: Oct 21, 2007
Posts: 8
Thank you very much. Should have clicked in my head but didn't.

~Adil.
Atwal Usha
Ranch Hand

Joined: Sep 10, 2009
Posts: 137
Hi,

Although Chinmaya has already made it clear still I would add a few lines to it. If no access specifier has been mentioned before a variable it does not mean that it will be private. By default the access specifier is Default which provides a package level access.



Java Certification Exam Mock Tests: SCJA  SCJP 5  SCJP 6  SCJP 6 (Online Training)  SCJP 6 (Instructor Led Training)   SCWCD 5   SCBCD 5  SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chapter 1 Question 8 Kathy & Bates book.
 
Similar Threads
Explanation...
Typo in Mcgraw-Hill SCJP 5 Book?
Problem related to enums
Kathy Sierra Chapter 1 Selftest question 4
Enums