File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes javacaps mock 2 Q:25 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "javacaps mock 2 Q:25" Watch "javacaps mock 2 Q:25" New topic
Author

javacaps mock 2 Q:25

Haining Mu
Ranch Hand

Joined: Jun 01, 2001
Posts: 51

Answer: C
I did see anything wrong with multiplication, the error is Initialization of variable "Integer", it need cast. so answer is D, right?
william shen
Ranch Hand

Joined: Jun 07, 2001
Posts: 60
The right answer should be C.Here need int cast to byte,then
byte Integer =byte(Byte * Double);should be ok.
Originally posted by Haining Mu:
[B]
Answer: C
I did see anything wrong with multiplication, the error is Initialization of variable "Integer", it need cast. so answer is D, right?[/B]


------------------
Amit Madan
Ranch Hand

Joined: Dec 20, 2000
Posts: 32
ans c is correct because
the value of Byte & Double is not final it may be changed so it is not definat that
multiplication of them will be in the range of byte(-128 to 127).so it give compile time error
if we made both of them final then it will run properly.
Amit Madan
Geoff Tate
Ranch Hand

Joined: Feb 06, 2001
Posts: 55
Amit,
I think the correct answer is that the all math operands are promoted to at least an int before being used in an operation. The operands are both promoted to ints causing the result to be an int which clearly will not fit in a byte. casting it should work. I don't see what final has to do with it.


<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR> fantastic, a towel? <HR></BLOCKQUOTE>
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Amit is very much right, if the variable(of integral data type) are declared as final and their operartion(i.e /, * , +, - etc) remain within their limits, casting is not required.


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Amit Madan
Ranch Hand

Joined: Dec 20, 2000
Posts: 32
Hi
binary numeric promotion implicitly appropriate widening primitive conversion so that a pair of operands have the broadest numeric type of two,but which is always at least int.
byte,short,char always converted to at least int.
here both of them are variable so they can be changed.so multiplication of them can be an integer which may be not in rang of byte so compiler give error with msg ossible loss of precision.so explisit casting requird where definatly loss of precision.
if you make them final then value of them are constant so it can't be changed and here multiplication is within the range of byte so then it work properly because no precision loss.
Amit Madan
 
Don't get me started about those stupid light bulbs.
 
subject: javacaps mock 2 Q:25