my dog learned polymorphism*
The moose likes Mock Exam Errata and the fly likes javaranch round up exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "javaranch round up exam" Watch "javaranch round up exam" New topic
Author

javaranch round up exam

ravi ckumar
Greenhorn

Joined: Dec 08, 2000
Posts: 18
in the round up exam it was given that if 2 primitives are compared then the lower is automatically get converted to the higher, so the answer was given to be true,
but boolean is also a primitive in java, but if u compare a boolean with any primitive then a compiler err is got
so i feel the answer is false
what say !!!
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
boolean can never be promoted to anything and you can't convert anything to a boolean. The rules for narrowing and widening apply to the other primitives.
Bill
Judy YU
Ranch Hand

Joined: Nov 19, 2000
Posts: 30
If the 2 primitive datatypes are byte and short, according to the answer, byte(lower) should be promoted to short(the higher), which is obviously wrong since both of them should be promoted to int. The answer should be false.
Judy
Pete Pan
Ranch Hand

Joined: Mar 14, 2001
Posts: 44
I agree with Judy. There is even a question about this with
byte a=1;
byte b=1;
byte c=a+b; //causes error because both are promoted

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi,
Judy and Peter. Read the question again. You both are confusing arithmetic with comparison. If the question had stated the following:
if 2 primitive are used in an arithmetic statement ...
But the question doesn't say that ...
Comparison is handled between 2 primitives by promoting the lower to the upper. This, of course, excludes boolean!
Regards,
Manfred.
Pete Pan
Ranch Hand

Joined: Mar 14, 2001
Posts: 44
I didn't mention boolean.
I am NOT confusing them?
byte b=1;
short s=2;
if(b==s)
{
// b and s are promoted to int
// s=s+b fails for loss of precission
// so if b are promoted for addition
// then they are both promoted for comparison
}

Originally posted by Manfred Leonhardt:
Hi,
Judy and Peter. Read the question again. You both are confusing arithmetic with comparison. If the question had stated the following:
if 2 primitive are used in an arithmetic statement ...
But the question doesn't say that ...
Comparison is handled between 2 primitives by promoting the lower to the upper. This, of course, excludes boolean!
Regards,
Manfred.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javaranch round up exam