I had a doubt regarding Casting Objects to one another I understood about implicit casting, But when it comes to explicit conversions when does it throw Compile time Error and when does it give Runtime Exception(Classcast Exception).
SCJP 5.0 95%<br /> <br />The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
Joined: Feb 19, 2007
Is this same even in case of Interfaces.... Does we get a class cast Exception when using Interfaces?
Does the same rules apply to casting objects to interfaces? [ February 19, 2007: Message edited by: Ravi Pinnaboyina ]
Javier Sanchez Cerrillo
Joined: Aug 02, 2006
Yes its the same.
Almost all in Java is the same between classes and interfaces (in that sense (is a relationship)), except for the "instanceof" operator in which you can use any interface after "instanceof" and you won't get compiler time error. But if you use a class that is not part of the hierarchy you get compiler error.