Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance-1  RSS feed

 
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
Boost this thread!