Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance-1

 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code:
---------------------------------------------------
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the specs for the instanceof operaor : if the left operand is null, result is always false.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic