File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

can u please explain the ouput of the given code

kapilg gupta

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

String sound;
Animals(String 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: 15084

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


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

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
I agree. Here's the link:
subject: can u please explain the ouput of the given code
It's not a secret anymore!