• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

enum doubt

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The answer, the mock exam says is (a).
Why not b & c. Please explain
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried the other two options when you compiled and ran the program? What error messages or results did you get? Please show some effort in solving the problem.

From what mock exam did you get this question?
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raja,
Here is the clue : All nested class are implicitly final(unless atleast one constant has a class body) and static.
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this question from
http://www.ejavaguru.com/scjp5freemockexam.php (8th question)

While compiling, I got the error message
"cannot find symbol"

that means, Personality cannot be accessed directly; it can be assessed through Colours.(Like inner class) Am i right?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

that means, Personality cannot be accessed directly; it can be assessed through Colours.(Like inner class) Am i right?


comiler changes the enums into class something similar to this.

[ November 23, 2006: Message edited by: Sanjeev Kumar Singh ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Sanjeev pointed out, Personality is a static nested enum of Colours, so to access it from outside Colours you must use Colours.Personality and Colours.Personality.EXPRESSIVE.
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote: "All nested class are implicitly final(unless atleast one constant has a class body)"

I think the above all is only in the context of Enum's inner classes. Also I didnt get "unless atleast one constant has a class body".

Thanks in advance for helping.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An enum type is implicitly final unless one of the constants has a constant-specific class body.

In this case the constant-specific class body defines an anonymous subclass of the enum type.

Enums
 
You may have just won ten million dollars! Or, maybe a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic