aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Roundup #13 answer explanation not totally right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Roundup #13 answer explanation not totally right" Watch "Roundup #13 answer explanation not totally right" New topic
Author

Roundup #13 answer explanation not totally right

Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
#13 Assume: byte a=3; byte b=2; What is the result
of: byte c=a+b;
Answer: compiler error
The result of arithmetic is always at LEAST an int,
so the compiler will ask for an explicit cast:
byte c = (byte) a + b; even though a and b are bytes.

Writing <byte c = (byte) a + b;> still gives you the same error!
It should rather states:
byte c = (byte) (a+b);
which works. If the aim was to work with byte values.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Roundup #13 answer explanation not totally right
 
Similar Threads
Doubt on Dan's Question
Confused in Assignment
What is the advantage of Arithmetic Assignment Operators like += over normal arithmetic operator?
Arithmetic promotion
inner classes