Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance-1 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Inheritance-1" Watch "Inheritance-1" New topic
Author

Inheritance-1

Ritu Kapoor
Ranch Hand

Joined: Oct 03, 2004
Posts: 101
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

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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Inheritance-1
 
Similar Threads
Doubt on instanceof operator
Operators and Precedence
instanceof operator
InstanceOf Doubt.
instanceof Comparison