Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valiveru mock exam errata, please explain correct answers...

 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one of these will compile and run ?
A.import java.awt.Button;
import java.lang.Runnable;
public class MyClass extends Button implements Runnable{
public void run(){
//Some valid Code
}
}
//ANSWER IS D AND A BUT I CHOSE
B.import java.awt.event.*;
import java.applet.Applet;

public class MyApplet extends Applet,WindowAdapter{
public void windowClosed(WindowEvent we){
//Some Valid Code
}
}
C.import java.lang.Runnable;

public class MyClass implements Runnable{
public void run(){
int i = 10
System.out.println("i = "+i);
}
}
D.import java.awt.event.*;
public class MyClass extends WindowAdapter
implements WindowListener{
public void windowClosed(WindowEvent we){
//Some Valid Code
}
}
//ANSWER IS A AND D, BUT I SAW NOTHING WRONG WITH C??

Question 19.
Given the code
1public class ThreadDemo extends Thread{
2 public void run(){
3System.out.println("Thread Started");
4//What Code ???
5 System.out.println("Done");
6 }
7 public static void main(String[] arg){
8ThreadDemo td = new ThreadDemo();
9td.start();
10 }
11}
Which of the following given code segment(s) below can be placed at line 4 to print both "Thread Started" and "Done" to the standard output.

A.suspend(); resume();
B.sleep(10000);
C.yield();
D.yield(); resume();
E.All the above

//ANSWER IS C AND D, BUT HOW CAN D WORK ? I THOUGHT RESUME ONLY WORKS WITH SUSPEND ?
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for u r 1 ques i guess C is also correct .bcos there is nothing wrong in what he has specified except for a missing semicolon after int i=10 but that would not be a reason
For u r second q ,thought resume works only with suspend , in this case it will ignore the call so it will print whatever folows. BUT I HAVE A DOUBT , y is B not correct .after 10 seconds wont it execute and print .idf not y.?
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunilkumar and sarim,
In the first question, C is not correct because there is no semicolon after int i = 10. Compiler will complain, so C is not correct. So the correct answers are A and D
In the second question, sleep(10000) cannot be placed in the code because sleep has to catch InterruptedException and in this code it does not. So the correct answers are C and D. Also, resume() has been deprecated, so the new exam shouldn't ask any questions on this.
bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic