• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.?
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic