How to prevent the ClassCastExceptions?

How to prevent the ClassCastExceptions?
A. By using instanceof
B. By using is-a check
C. By using arrow operator with check function
D. By checking type of conversion
 
Answer: a
Explanation: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.
 

Tìm kiếm

Back
Top