1.

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 conversionI have been asked this question during an interview.The above asked question is from Downcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right CHOICE is (a) By using INSTANCEOF

For 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.



Discussion

No Comment Found

Related InterviewSolutions