This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes can u please explain the ouput of the given code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

can u please explain the ouput of the given code

kapilg gupta
Greenhorn

Joined: Jun 14, 2006
Posts: 10
enum Animals {

DOG("Woof"),CAT("meow"),FISH("burble");
String sound;
Animals(String s)
{
sound=s;
}
}
class TestEnum {
static Animals a;
public static void main(String args[])
{
System.out.println(a.DOG.sound +" "+a.FISH.sound);
}
}
output:-woof burble
i want to ask that when sound is assigned the value here as we have not
called constructor also which statement is rsponsible for invoking the constructor
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

This is the same question, just stated a little differently.
I already answered in your other thread.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
I already gave the reply of your question.

Duplicate Post

Please don't post it again

If you have any query, please post in the same thread

regards


Naseem
[ June 16, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can u please explain the ouput of the given code
 
Similar Threads
Interface question....
Static object
please explain the code and please anyone give example of overloading in enum
enum constructor problem
Kathy Sierra Chapter 1 Selftest question 4