//output yes.can anyone please explain the above two programs working for me to get.Both problems i have used ,object reference conversion rules.do i need to use anywhere explicit casting rules.if so ,please explain it for me to get.
The instanceof operator uses the true runtime type of the object, and returns a boolean based on whether the object's reference could be cast to the indicated type without throwing a ClassCastException.
In your second example, you have X myx = new Objective23(); The variable holding the reference is of type X, but the true runtime type of the object is Objective23 (because that's what was actually created with the constructor call).
So when evaluating x instanceof Objective23, the question is: Given the true runtime type of the object, could the reference be cast to type Objective23 without throwing a ClassCastException? [ January 16, 2007: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
posted 13 years ago
Here,how it is worked if we give the o as the referencetype only.For that o,How can we get the runtime Object to cast to NewCar. please help me further on this since not getting this properly i have refereed a lot of materials.but still having trouble. the output is nothing.so false is getting executed.but how.
[ January 17, 2007: Message edited by: Shiva Mohan ] [ January 17, 2007: Message edited by: Shiva Mohan ]
Why are you checking if "null" is an instance of anything? It is a special case, as it is a object literal that is meant to represent nothing. If null is an option, you should check to see if it is null first.
The JVM won't complain when you try to cast "null" to any type of object (because there is nothing to cast), and will return that it is *not* an instance of any type of object (because there is no object).
Henry [ January 17, 2007: Message edited by: Henry Wong ]