Tuesday, 16 June 2009

Java Certification Question 0006

Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus



Answer:
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
The instanceof operator can only be used to make a static comparison with a class type. Java1.1 added the isInstance method to the class Class to allow you to dynamically determine a class type. The exam does not test you on isInstance.

No comments: