Java认证模考试题(七)
文章作者 100test 发表时间 2007:03:14 17:02:45
来源 100Test.Com百考试题网
Question: 38
The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:
Person
|
---------------
| |
Student Teacher
There is the following expression in a Java source file:
Person p = new Teacher().
Which of the following expressions return true?
A. p instanceof Teacher
B. p instanceof Student
C. p instanceof Person
D. None of them returns true
Explanation:
The instanceof operator is used to test the type of an object. Because the reference p refers to a Teacher object and the Teacher is a subclass of the Person class the expressions in answer A and C will return true.
Correct Answer: A,C 38 of 60