Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interesting code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interesting code" Watch "interesting code" New topic

interesting code

vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
class interest
public static void main(String as[])
byte b=1;
case 5:
System.out.println("Hai I am FIVE");
case 10:
System.out.println("Hai I am TEN");
System.out.println("Hai I am DEFAULT");

Guys this is one of intersting code i went thru, when i simply work thru

Try it............if not i will be with u for answer
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Hi Vidya,
Default is treat as label. But switch case matches default Label.
So nothing prints here. Am I correct?

[ April 09, 2005: Message edited by: Raghu Shree ]

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
Ram Naresh

Joined: Mar 28, 2005
Posts: 11
Hi Vidya,
I think java takes 'Default' as a label rather than a keyword 'default'. So try using 'default' instead of Default.
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Shouldn't it give a compilation error. Default is not a legal case label.
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
That the answer i expect from U all Guys
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi vidya
i tried using the different type other thant the int.
i can't able to use the double in the switch case.
is the int is the only type used in the switch or any other type we can use.
v nithya

Joined: Mar 30, 2005
Posts: 3
we can use int,short,char,byte(within the range) in the switch statement.
sethu chiyan

Joined: Apr 05, 2005
Posts: 10

Nithya U r xactly right,

Vidya, The answer is nothing, because it takes Default simply as label not as default.

with regards,
I agree. Here's the link:
subject: interesting code
It's not a secret anymore!