Forums Register Login

Enums

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
ya ramesh is correct
+Pie Number of slices to send: Send
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
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1041 times.
Similar Threads
Problem related to enums
Chapter 1 Question 8 Kathy & Bates book.
can u please explain the ouput of the given code
Static object
Typo in Mcgraw-Hill SCJP 5 Book?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:51:38.