aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B master exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B master exam question" Watch "K&B master exam question" New topic
Author

K&B master exam question

Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
Hi All,




how the output is good

following are options 1)Good 2)Bad 3)Ugly 4)Compilation fails

Source K&B : Master Exam
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Here is a piece of code that might help you understand what is going on



Relate the output with the positive, negative or zero return value of the compare() method.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Chad Cook
Greenhorn

Joined: Dec 02, 2004
Posts: 29
Characters can be implicitly cast to integers. 'B' has a value of 66, 'G' of 77 and 'U' of 85. Thus, when you compare, for example, Good and Bad, it is actually returning 77 - 66, which returns a positive number.
Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
Thanks .I got it
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

Chad Cook wrote:Characters can be implicitly cast to integers. 'B' has a value of 66, 'G' of 77 and 'U' of 85. Thus, when you compare, for example, Good and Bad, it is actually returning 77 - 66, which returns a positive number.


Just to nit pick the comparison is done on the second character, not the first one, and the second character of the second word is used first. Sorry
Chad Cook
Greenhorn

Joined: Dec 02, 2004
Posts: 29
Good catch, and please nit pick.

Attention to detail is important when studying for the exam.
 
jQuery in Action, 2nd edition
 
subject: K&B master exam question