Students, it’s time to take a closer look at the hint of programming in java NPTEL week 6 assignment answers. And, identify where you can improve your marks in this assignment.

NPTEL Programming In Java Week 6 Assignment Answers
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()
1000+ Students are taking advantage of instant notifications on telegram.
Q2. Which of the following statement is true in case of starting a thread with ‘run()’ and ‘start()’ method?
a. There is no difference between starting a thread with ‘run()’ and ‘start()’ method.
b. When you call start() method, main thread internally calls run() method to start newly created Thread
c. When you call run() method directly no new Thread is created and code inside run() will execute on current Thread.
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. By implementing the Runnable interface.
b. By extending the Thread class.
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. a ArithmeticException
c. ArithmeticException Exception Hello World
d. ArithmeticException Hello World
e. none
Answer: d. ArithmeticException Hello World
Q5. Which method restarts a dead thread
a. start()
b. restart()
c. restartThread()
d. none
Answer: d. none
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 tl-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: Option D.
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 True
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: Option B, C, and 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
TELEGRAM FOR NOTIFICATION | Click Here |
Follow on Google News (in one click) | Click Here |
Disclaimer: These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.
Also Available: