aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance of operator 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 "instance of operator" Watch "instance of operator" New topic
Author

instance of operator

cybel sheriden
Ranch Hand

Joined: Jan 18, 2005
Posts: 50
hi

instance of test can be don on obj ref variable ,to see if they are of a class or interface type.

i didn't understand the last three test(Foo[], Foo[1]) in table 3-2 (page 159 of K&B)
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
One key fact is that the element type, Foo, is different from the array type, Foo[].
If we say "Foo[] f;", then f is of type Foo[] but f is not of type Foo. f[1] is of type Foo.

The other key fact is that every array type is a subclass of Object[] and Object[] is a subclass of Object, so every array type is a subclass of Object.
[ February 22, 2005: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
From Mike,
The other key fact is that every array type is a subclass of Object[] and Object[] is a subclass of Object, so every array type is a subclass of Object.


Mike, i guess this statement should be true only for array of reference types. I mean any integer array(int[]) is not a subclass of Object[].
Please let me know if i am wrong

Thanks
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Mike, i guess this statement should be true only for array of reference types. I mean any integer array(int[]) is not a subclass of Object[].
Please let me know if i am wrong

You are correct. I forgot about arrays of primitives. They are subclasses of Object but not Object[].
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance of operator
 
Similar Threads
Object constructor and initialization
What do you mean by memory leak in Java?
Is there any way an initialized instance knows who initialized it without passing information to it?
instanceOf explanation needed
Inheritance Question