• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enums

 
Gustavo Villegas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get why this is right
Chapter 1 Question 8 SCJP K&B 5.0



What is the Result

A Woof Burble
B Multiple Compilation Errors
C Compilation Fails line 2
D Compilation Fails line 3
E Compilation Fails line 4
F Compilation Fails line 9

I though the answer was F but the the Answer is A...

I don't understand why :S

I think that A should have some value before we can use it or something.

Accessing the Elements of an Enum is like Accessing Class Variables ??
I mean, doing something like this is similar?.


[ August 31, 2008: Message edited by: Gustavo Villegas ]
 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Compiler creates static final variables with enum variables, that is the reason we can access them with enum name, compiler generates code like below

 
ankit kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya ramesh is correct
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general tip I have to recommend testing this sort of thing yourself!

We've listened to thousands of ranchers who studied for these Sun Java exams, and everyone who does really well writes LOTS and LOTS of code while they are studying. So this would be a case where you should type the code in, FROM THE COMMAND LINE and NOT an IDE, and test it. Then, once you've typed in what's in the book, play around with it - change stuff, try stuff out, and experiment. That's how you're really going to learn this stuff.

Finally, I can say that the teams that create these tests write and test LOTS of code (from the command line), while the questions are being created. And, Kathy and I write and test LOTS of code while we're writing our books.

Being a good programmer is like being a good tennis player. You can't just read about hitting tennis balls, you have to go out on the court and hit a lot of tennis balls.

hth,

Bert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic