File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan Mock question 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 "Dan Mock question" Watch "Dan Mock question" New topic

Dan Mock question

Sam Zou
Ranch Hand

Joined: Nov 18, 2002
Posts: 40
I have a question about Dan Mock Study Guide exam.
Ths question is from the Study Guide Exam A , question 14,

In the answer it said:
....However, if it is cast to a byte then it is reduced to eight bitsthat are all set to one...

It is the reduced to eight bits that I don't understand. In general case, when there's a narrowing conversion, in our case to byte, do we always take the 8 less significant bits ?

Sam<p>"Life is difficult"<br /> -Scott Peck-</p>
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

I doubt the opposite result is what anyone would expect. By narrowing the value you eliminate the portion of the original value that doesn't fit in the range of the narrower type.
There is a presumption that type narrowing isn't generally used to alter the value; usually you just want to eliminate zero-padding that occurs because the VM memory model wants to manage 32-bit values internally and leave the type management of "sub-integers" to the programmer.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: Dan Mock question
It's not a secret anymore!