File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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: 13875
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InstanceOf Doubt.
 
Similar Threads
StringBuffer...
Unreachable Code
constructor..
doubt in casting
Exception..