Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

can u please explain the ouput of the given code

 
kapilg gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the same question, just stated a little differently.
I already answered in your other thread.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
    Bookmark Topic Watch Topic
  • New Topic