Oopj Quiz 5 IT - A

10 Questions | Total Attempts: 83

SettingsSettingsSettings
Java Quizzes & Trivia

.


Questions and Answers
  • 1. 
    In Java, each thread has its own ________, in which it runs?
    • A. 

      Main() method

    • B. 

      JVM

    • C. 

      Call stack

    • D. 

      Memory

  • 2. 
    In Java, by default every thread is given a _________.
    • A. 

      MIN_PRIORITY(0)

    • B. 

      NORM_PRIORITY(5)

    • C. 

      MAX_PRIORITY(10)

    • D. 

      HIGH_PRIORITY(7)

  • 3. 
    What will happen if we call run() directly, without start() ?
    • A. 

      Program will give a compilation error.

    • B. 

      Nothing will happen both the methods are same.

    • C. 

      Runtime error.

    • D. 

      Thread won't be allocated a new call stack, and start running in the current call stack.

  • 4. 
    Which two are valid constructors for Thread class ? 1. Thread(Runnable r, String name) 2. Thread() 3. Thread(int priority) 4. Thread(Runnable r, ThreadGroup g)
    • A. 

      1,2

    • B. 

      1,3

    • C. 

      2,3

    • D. 

      2,4

  • 5. 
    What Exception is thrown when you start a thread twice ?
    • A. 

      InterruptedException

    • B. 

      NullPointerException

    • C. 

      IOException

    • D. 

      IllegalStateException

  • 6. 
    Which class or interface defines the wait(), notify(), and notifyAll() methods
    • A. 

      Object

    • B. 

      Thread

    • C. 

      Runnable

    • D. 

      Class

  • 7. 
    What is the Output of given code ? class MyThread extends Thread { public static void main(String[] args) { MyThread my = new MyThread(); Thread t = new Thread(my); t.start(); } public void run() { for(int i=0; i< 3; i++){ System.out.println(i+"..") } } }
    • A. 

      Compilation fails

    • B. 

      1..2..3..

    • C. 

      0..1..2..3

    • D. 

      0..1..2..

  • 8. 
    Which of the following statement is not correct ?
    • A. 

      Thread is a light weight process.

    • B. 

      Sleep() is a non-static method simply used to put your thread on sleep.

    • C. 

      Sleep() is a static method simply used to put your thread on sleep.

    • D. 

      The notifyAll() method must be called from a synchronised context.

  • 9. 
    What will be the Output of given code ? public class Test implements Runnable { public void run() { System.out.println("r1 "); System.out.println("r2 "); } public static void main( String[] args ) { Thread t = new Thread(new Test()); t.start(); System.out.println("m1 "); t.join(); System.out.println("m2 "); } }
    • A. 

      Compilation error.

    • B. 

      The output would be r1 r2 m1 m2

    • C. 

      The output would be m1 m2 r1 r2

    • D. 

      The output would be m1 r1 r2 m2

  • 10. 
    Give One Word for ? A situation where two or more threads are blocked forever and waiting for each other to release resources.
    • A. 

      Critical Section

    • B. 

      Mutual Exclusion

    • C. 

      Deadlock

    • D. 

      Synchronization

Back to Top Back to top