Programming in Java | NPTEL | Week 6 quiz solutions

This set of MCQ(multiple choice questions) focuses on the Programming in Java NPTEL Week 6 Solutions.

Course layout (Answers Link)

Answers COMING SOON! Kindly Wait!

NOTE: You can check your answer immediately by clicking show answer button. Programming in Java NPTEL Week 6 Solutions” contains 10 questions.

Now, start attempting the quiz.

Programming in Java NPTEL Week 6 Solutions

Q1. Which of the following is NOT a method of the Thread class in Java?

a) isInterrupted ()
b) interrupt ()
c) joins ()
d) sleep ()

Answer: c) joins ()

Programming in Java NPTEL Week 6 Solutions

Q2. Which of the following statement(s) is/are true?

a) public int getId() : returns the id of the thread.
b) public boolean isAlive() : tests if the thread is alive.
c) public void interrupt() : interrupts the thread.
d) public boolean isInterrupted() : tests if the thread has been interrupted.

Answer: a), b), c), d)

Q3. Which of the following can be used to create an instance of Thread?

a) By implementing the Runnable interface.
b) By extending the Thread class.
c) By creating a new class named Thread and calling method run ().
d) By importing the Thread class from package.

Answer: a), b)

Programming in Java NPTEL Week 6 Solutions

Q4. What is the output of the following program?

a) Hello World
b) 5
c) Compile time error
d) ArithmeticException

Answer: c) Compile time error

Q5. Which one of these keywords must be used to handle the exception thrown by try block in some rational manner?

a) try
b) finally
c) throw
d) catch

Answer: d) catch

Programming in Java NPTEL Week 6 Solutions

Q6. Assume the following method is properly synchronized and called from a thread A on an object B: wait(200); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

a) After thread A is notified, or after two seconds.
b) Two seconds after thread A is notified.
c) After the lock on B is released, or after two seconds.
d) Two seconds after lock B is released.

Answer: a) After thread A is notified, or after two seconds.

Q7. The following is a simple program using the concept of thread.
What is the output of the above program?

a) 1
3
b) 1
2
3
4
c) Runtime error
d) 1
2

Answer: a)

Q8. For the program given below, what will be the output after its execution?

a) 0
b) true
c) 1
d) false

Answer: c) 1

Programming in Java NPTEL Week 6 Solutions

Q9. Which of the following is a correct constructor for a thread object?

a) Thread(Runnable a, String str);
b) Thread(Runnable a, int priority);
c) Thread(Runnable a, ThreadGroup t);
d) Thread(int priority);

Answer: a) Thread(Runnable a, String str);

Q10. Which of these keyword(s) is used to manually throw an exception?

a) try
b) finally
c) throw
d) catch

Answer: c) throw

Programming in Java NPTEL Week 6 Solutions

Programming in Java NPTEL Week 6 Solutions

Q1. Which of the following is NOT a method of the Thread class in Java?

a) public void run()
b) public void exit()
c) public void start()
d) public final int getPriority()

Answer: b) public void exit()

Programming in Java NPTEL Week 6 Solutions

Q2. What is difference between starting thread with run() and start() method?

a) There is no difference
b) When you call start() method, main thread internally calls run() method to start newly created Thread
c) run() calls start() method internally
d) None

Answer: b) When you call start() method, main thread internally calls run() method to start newly created Thread

Q3. Which of the following can be used to create an instance of Thread?

a) By implementing the Runnable interface
b) By extending the Thread class
c) By creating a new class named Thread and calling method run()
d) By importing the Thread class from package

Answer: a), b)

Programming in Java NPTEL Week 6 Solutions

Q4. What is the output of the following program?

public class Question
{
   public static void main(String[] args) {
      try {
          int a = 5/0;
          System.out.print("a");
      } catch (ArithmeticException ae) {
             System.out.print("ArithmeticException ");
        }catch (Exception e) {
             System.out.print(" Exception ");
     }
        System.out.print("Hello World");
   }
}

a) Hello World
b) ArithmeticException
c) ArithmeticException Exception Hello World
d) ArithmeticException Hello World

Answer: d) ArithmeticException Hello World

Q5. Which method restarts a dead thread

a) start()
b) restart()
c) restartThread()
d) none

Answer: d) none

Programming in Java NPTEL Week 6 Solutions

Q6. Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

a) After thread A is notified, or after two seconds
b) Two seconds after thread A is notified
c) After the lock on B is released, or after two seconds
d) Two seconds after lock B is released

Answer: a) After thread A is notified, or after two seconds

Q7. The following is a simple program using the concept of thread.

public class Question extends Thread{
  public void run(){
     for(int i=1; i<5; i++) {
        System.out.println(++i);
     }
  }
  public static void main(String args[]) {
     Question t1 = new Question();
     t1.run();
  }
}

What is the output of the above program?

a) 1
     3
b) 1
     2
     3
     4
c) Runtime error
d) 2
     4

Answer: d)

Programming in Java NPTEL Week 6 Solutions

Q8. For the program given below, what will be the output after its execution?

public class Main{
  public static void main(String[] args) {
     Thread thread = Thread.currentThread();
     System.out.print(thread.activeCount());
     thread.run();
     System.out.print(thread.activeCount());
   }
}

a) 01
b) False Ture
c) True True
d) 11

Answer: d) 11

Q9. Which of the following is/are not a correct constructor for a thread object?

a) Thread(Runnable a, String str);
b) Thread(Runnable a, int priority);
c) Thread(Runnable a, ThreadGroup t);
d) Thread(int priority);

Answer: b), c), d)

Q10. Which exception is thrown when an array element is accessed beyond the array size?


a) ArrayElementOutOfBounds
b) ArrayIndexOutOfBoundsException
c) ArrayIndexOutOfBounds
d) None of these

Answer: b) ArrayIndexOutOfBoundsException

Q11. Which of these keywords is/are a part of exception handling?

a) try
b) finally
c) thrown
d) catch

Answer: a), b), d)

Programming in Java NPTEL Week 6 Solutions

>> Next- Programming in Java Week 5 Assignment Solutions

>> Next- Programming in Java Week 7 Assignment Solutions


DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

Leave a Comment

Your email address will not be published. Required fields are marked *