Oopj Quiz 5 IT - A

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Anurag
A
Anurag
Community Contributor
Quizzes Created: 1 | Total Attempts: 105
Questions: 10 | Attempts: 105

SettingsSettingsSettings
Oopj Quiz 5 IT - A - Quiz

.


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

    Correct Answer
    C. Call stack
    Explanation
    Moon is round because of formed and collapsed under the force of their own gravity.

    Rate this question:

  • 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)

    Correct Answer
    B. NORM_PRIORITY(5)
    Explanation
    In Java, every thread is given a priority level by default. The priority level determines the importance of the thread and how it should be scheduled by the operating system. The available priority levels are MIN_PRIORITY(0), NORM_PRIORITY(5), and MAX_PRIORITY(10). The NORM_PRIORITY(5) is the default priority level assigned to threads in Java. This means that unless explicitly specified, a thread will have a normal priority level of 5.

    Rate this question:

  • 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.

    Correct Answer
    D. Thread won't be allocated a new call stack, and start running in the current call stack.
    Explanation
    If we call the run() method directly without using the start() method, the thread won't be allocated a new call stack. Instead, it will start running in the current call stack. This means that the code inside the run() method will be executed just like any other regular method call, without any separate thread being created. This is different from using the start() method, which creates a new thread and then calls the run() method in that new thread.

    Rate this question:

  • 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

    Correct Answer
    A. 1,2
    Explanation
    During the night the high contrast between the bright moon and the night's dark skies make the Moon look white.

    Rate this question:

  • 5. 

    What Exception is thrown when you start a thread twice ?

    • A.

      InterruptedException

    • B.

      NullPointerException

    • C.

      IOException

    • D.

      IllegalStateException

    Correct Answer
    D. IllegalStateException
    Explanation
    When you start a thread twice, it will throw an IllegalStateException. This exception is thrown when a method is called at an illegal or inappropriate time. In this case, starting a thread that is already running is considered illegal and will result in an IllegalStateException being thrown.

    Rate this question:

  • 6. 

    Which class or interface defines the wait(), notify(), and notifyAll() methods

    • A.

      Object

    • B.

      Thread

    • C.

      Runnable

    • D.

      Class

    Correct Answer
    A. Object
    Explanation
    The correct answer is Object because the wait(), notify(), and notifyAll() methods are defined in the Object class in Java. These methods are used for inter-thread communication and synchronization. The wait() method is used to make a thread wait until another thread notifies it, while the notify() method is used to wake up a single waiting thread, and the notifyAll() method is used to wake up all the waiting threads. These methods are fundamental for implementing thread synchronization and coordination in Java.

    Rate this question:

  • 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..

    Correct Answer
    D. 0..1..2..
    Explanation
    The code creates a class called MyThread which extends the Thread class. In the main method, an instance of MyThread is created and then a new Thread object is created, passing the MyThread instance as a parameter. The start() method is called on the Thread object, which causes the run() method of the MyThread instance to be executed.

    In the run() method, a for loop is used to print the values of i from 0 to 2, followed by a ".." string. Therefore, the output of the code will be "0..1..2..".

    Rate this question:

  • 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.

    Correct Answer
    C. Sleep() is a static method simply used to put your thread on sleep.
    Explanation
    The correct answer is "sleep() is a static method simply used to put your thread on sleep." This statement is not correct because sleep() is a non-static method that is used to put a thread on sleep. Static methods are called on the class itself, while non-static methods are called on an instance of the class.

    Rate this question:

  • 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

    Correct Answer
    A. Compilation error.
    Explanation
    The code will result in a compilation error because the Test class does not implement the required method from the Runnable interface, which is the run() method.

    Rate this question:

  • 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

    Correct Answer
    C. Deadlock
    Explanation
    A deadlock occurs when two or more threads are unable to progress because each thread is waiting for a resource that is held by another thread. In this situation, the threads are blocked indefinitely and cannot continue their execution. This can happen when there is a circular dependency between the threads, causing them to wait for each other's resources without being able to release their own.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 13, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 21, 2018
    Quiz Created by
    Anurag
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.