Question
Which of the following statements is correct? (Choose one.)
- A. Only primitives are converted automatically; to change the type of an object reference, you have to do a cast.
- B. Only object references are converted automatically; to change the type of a primitive, you have to do a cast.
- C. Arithmetic promotion of object references requires explicit casting.
- D. Both primitives and object references can be both converted and cast.
- E. Casting of numeric types may require a runtime check.
D.
Note
D is correct because in Java primitives and object references can be both converted and cast.
A and B are wrong because they contradict D.
C is wrong because objects do not take part in arithmetic operations.
E is wrong because only casting of object references potentially requires a runtime check.
PreviousNextRelated