Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SCJP question 2
10-22-2008, 12:13 AM
Post: #1
SCJP question 2
Given:

public class Test{
public enum Dogs{collie,harrier,shepherd};
public static void main(String [] args){
Dogs myDog=Dogs.shepherd;
switch(myDog)
{
case collie:
System.out.print("collie");
case default:
System.out.print("retreiver");
case harrier:
System.out.print("harrier");
}
}
}

what would be the output of this program? Would it print retreiver harrier or would it give a compilation error?
Find all posts by this user
Quote this message in a reply
10-22-2008, 02:12 AM
Post: #2
RE: SCJP question 2
Your code is not compiling in my machine. To compile the file I changed case default to just default . So now the code will be
[java]
switch(myDog)
{
case collie:
System.out.print("collie");
default:
System.out.print("retreiver");
case harrier:
System.out.print("harrier");
}
[/java]

And the above code will print
retreiver
harrier
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SCJP practice question priyaguptan 6 92 10-22-2008 01:45 AM
Last Post: albinjoseph

Forum Jump: