Guys lets remember the following points:
The question is basically asking what are the possible i/p parameters that can be passed to the Thread constructor. Now looking from the option we might be tempted to just choose (a) and (d). But, remember that there is a constructor Thread(String s) (u can refer to the api for details). Therefore, with given options the instanceof operator must return true for
(A) - coz Thread class does implement Runnable interface. So, an instance of Thread class would very well be coverted to Runnable.
i.e Runnable r = new Thread(); So, (A) must give true. Beena, I guess this must clarify your doubt.
(B)& (C) - I guess there is no probs for anyone with it.
(E) - coz u have a constructor Thread(String s). So the expression with instanceof must return True.
Therefore my answers would be (a), (d), (e).
Now Dilip, u r wondering why your last 2 lines of code is giving u probs - well, besides the regular rules about instanceof operator, remember when u have:
(LHS) instanceof (RHS) //////////// LINE 1
Then LHS must be castable to RHS during compile time. If this is not satisfied there woud be no circumstance during runtime under which LINE 1 would be true. Therefore,
java first verifies the possiblity of casting LHS to RHS.
Therefore, in your code "this" - i.e an instance of Class1 is neither a subclass or superclass of Thread nor of String class.
So, there is no way you can cast an instance of class1 to Thread or String. So, your last 2 lines of code gives cimpiler error producing an apt error message explaning the scenario.
Hope this helps
Of course, in case anybody disgress please raise it so that all of can be get our fundamentals correct
-sampaths77
(I) About Threads first:
Thread has a constructor: Thread(String S)