aspose file tools*
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
Author

interesting code

vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
class interest
{
public static void main(String as[])
{
byte b=1;
switch(b)
{
case 5:
System.out.println("Hai I am FIVE");
case 10:
System.out.println("Hai I am TEN");
Default:
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?
cheers!!!

[ 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="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
Ram Naresh
Greenhorn

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.
Ram
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
Greenhorn

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

Joined: Apr 05, 2005
Posts: 10
Hi,

Nithya U r xactly right,

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

with regards,
Chiyan
 
jQuery in Action, 2nd edition
 
subject: interesting code