0

programming languages Online Quiz - 108

Description: programming languages Online Quiz - 108
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which interface does TreeMap class implement ?

  1. Set

  2. SortedSet

  3. List

  4. Tree

  5. SortedMap


Correct Option: E

A monitor called nik has 3 threads, having same priority, in its waiting pool; How can we notify one of the threads, named 'thread1' to move from Waiting state to Ready State?

  1. Execute notify(thread1); from within synchronized code of mon.

  2. Execute mon.notify(thread1); from synchronized code of any object.

  3. Execute thread1.notify(); from synchronized code of any object.

  4. Execute thread1.notify(); from any code(synchronized or not) of any object.

  5. You cannot specify which thread will get notified.


Correct Option: E
  1. The program exits via a call to System.exit(0);

  2. Another thread is given a higher priority.

  3. A call to the thread's stop method.

  4. A call to the halt method of the Thread class.


Correct Option: D

Which statement is true for the following code? public class Rpcraven { public static void main(String argv[]){ Pmcraven pm1 = new Pmcraven("one"); pm1.run(); Pmcraven pm2 = new Pmcraven("two"); pm2.run(); } } class Pmcraven extends Thread { private String sTname=""; Pmcraven(String s) { sTname = s; } public void run(){ for(int i =0; i < 2 ; i++){ try { sleep(1000); }catch(InterruptedException e){ } yield(); System.out.println(sTname); } } }

  1. Compile time error, class Rpcraven does not import java.lang.Thread

  2. Output of One One Two Two

  3. Output of One Two One Two

  4. Output of One Two Two One


Correct Option: B
  1. Runtime Exception

  2. finally block will be executed

  3. finally block will not be executed

  4. Compilation error in else block


Correct Option: C
  1. Execute notify(thread1); from within synchronized code of mon.

  2. Execute mon.notify(thread1); from synchronized code of any object.

  3. Execute thread1.notify(); from synchronized code of any object.

  4. Execute thread1.notify(); from any code(synchronized or not) of any object.

  5. You cannot specify which thread will get notified.


Correct Option: E

What of the following fails to cause a thread stop executing ?

  1. The program exits via a call to System.exit(0);

  2. Another thread is given a higher priority.

  3. A call to the thread's stop method.

  4. A call to the halt method of the Thread class.


Correct Option: D
  1. A compile time error indicating that no run method is defined for the Thread class.

  2. A run time error indicating that no run method is defined for the Thread class.

  3. Clean compile and at run time the values 0 to 9 are printed out.

  4. Clean compile but no output at runtime.


Correct Option: D

What will be the output of the following program? package scjp.threadTest; public class Ques01 { public static void main(String[] args) { HelloThread hello = new HelloThread(); hello.start(); } } class MyThread implements Runnable{ @Override public void run() { System.out.println("My thread"); } } class HelloThread extends Thread{ public void start(){ System.out.println("Hello thread"); } public void run(){ Thread thread = new Thread(new MyThread()); thread.start(); } }

  1. The program will output 'Hello Thread' and 'My Thread'.

  2. The program will output 'Hello Thread'.

  3. The program will output 'My Thread' and 'Hello Thread'.

  4. The order of the outputs is not will vary upon execution.


Correct Option: B

How does the set collection deal with duplicate elements?

  1. An exception is thrown if you attempt to add an element with a duplicate value.

  2. The add method returns false if you attempt to add an element with a duplicate value.

  3. A set may contain elements that return duplicate values from a call to the equals method.

  4. Duplicate values will cause an error at compile time.


Correct Option: B

Is this code legal ? class ExceptionA extends Exception {} class ExceptionB extends ExceptionA {} public class Test{ void thrower() throws ExceptionB{ throw new ExceptionB(); } public static void main(String[] args){ Test t = new Test(); try{t.thrower();} catch(ExceptionA e) {} catch(ExceptionB e) {} } }

  1. yes

  2. no

  3. DO NOT SELECT 1

  4. DO NOT SELECT 2


Correct Option: B
- Hide questions