I have a small suggestion.I have observed in this list that
a same set of Tricky Questions from various Mock Exams Crop
up again and again.Shall we make a list in this thread
of all the Tricky Questions/Questions related to fundamentals
we find,without repeating any of them so that we have a consolidated list of Questions Also, We should put only the hardest questions and their answers.Also if we have to discuss about any of the questions in this list ,we should do it in a different Thread ,so That this thread does not get Cluttered.
To start The Thread I add a question I felt tested your fundamentals
Q 1)
class ApBase extends Object implements Runnable.
1. Apbase aBase = new ApBase();
2. Runnable aR = aBase;
3. Object obj = aR;
4. Apbase x = (Apbase)obj;
What will happen when we try to compile and run?
a. Compiler objects to line 2.
b. Compiler objects to line 3.
c.Code compiles but when run , throws ClassCastException in line 4.
d. Compiles and runs fine.
Answer --> D
Another Question
Q2
Which of the options below will print
running on the Command Line
1. class RunTest implements Runnable {
2. public static void main(String args[]) {
3. RunTest rt = new RunTest();
4. Thread t = new Thread(rt);
5. //A
6. }
7. public void run() {
8. System.out.println("running");
9. }
10. void go() {
11. start(1);
12. }
13. void start(int i) {
14. }
15. }
Select all valid answers.
a. System.out.println("running");
b. rt.start();
c. rt.go();
d. rt.start(1);
Ans--> a
[This message has been edited by Prasanna Joshi (edited June 30, 2000).]
[This message has been edited by Prasanna Joshi (edited June 30, 2000).]