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 instanceof and casts 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 "instanceof and casts" Watch "instanceof and casts" New topic

instanceof and casts

Anna Dow

Joined: Jun 04, 2002
Posts: 18
Hi, all,
here is my question:
It looks that if returned true, then the cast is always possible.
(That is, the code like:

will never give a ClassCastException.) Is it true ?
Thanks, Anna
Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93
Yeah thats true.
But the code which you gave wont compile
coz you didn't use the if statement properly

should be made

I agree. Here's the link:
subject: instanceof and casts
It's not a secret anymore!