This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes InstanceOf Doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "InstanceOf Doubt." Watch "InstanceOf Doubt." New topic

InstanceOf Doubt.

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Here the answer is null,false,false.But null IS-A Object, then why is the answer false?

1 class AA{}
2 class BB extends AA{}
3 class Q6
4 {
5 public static void main(String arg[])
6 {
7 AA a=null;
8 BB b=(BB)a;
9 System.out.println(b);
10 System.out.println(b instanceof BB);
11 System.out.println(b instanceof AA);
12 }
13 }
Ankit Garg

Joined: Aug 03, 2008
Posts: 9453

null instanceof any type will always result in false. You can read the Java Language Specification for that...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15042

Originally posted by Abhi vijay:
But null IS-A Object...

No, null is not an object in Java. Where did you hear or read that null is an object?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: InstanceOf Doubt.
jQuery in Action, 3rd edition