SCJP -- about instanceof operator
The contractor has started a Ticker class to post the company stock price.
import java.awt.*;
class Ticker extends Component {
public static void main (String [] args) {
Ticker t = new Ticker();
// Insert statement here
}
}
Which of the following statements could legally be inserted into this code? (Choose all that apply.)
A. boolean test = (t instanceof Ticker);
B. boolean test = t.instanceof(Ticker);
C. boolean test = (t instanceof Component);
D. boolean test = t.instanceof(Object);
E. boolean test = (t instanceof String);
正确答案应该是A、C。为什么E不对?请展开讨论!