jQuery in Action, 3rd edition
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
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
Source: http://www.go4java.20m.com/mock1.htm
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: 9462

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: 15081

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: http://aspose.com/file-tools
subject: InstanceOf Doubt.
It's not a secret anymore!