aspose file tools*
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 Spring in Action this week in the Spring 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: 14269
    
  21

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 8 API documentation
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