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 ?