This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance-1 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 "Inheritance-1" Watch "Inheritance-1" New topic


Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 102
class AA {

class BB extends AA {

class Class24 {
public static void main(String arg[]) {
AA a = null;
BB b = (BB) a;
System.out.println(b instanceof AA);
System.out.println(b instanceof BB);

Output: false,false

Query: Why the output is false for the above code. Please give explanation for that.
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Regarding the specs for the instanceof operaor : if the left operand is null, result is always false.

Regards,<br />Seb<br /> <br />SCJP 1.4
I agree. Here's the link:
subject: Inheritance-1
It's not a secret anymore!