Programming In Java Week 6 NPTEL Assignment Answers 2025

NPTEL Programming In Java Week 6 Assignment Answers 2024

Q1. What is the output of the following program?
a. “Programming In Java”
b. Run time error
c. Compile time error
d. ArithmeticException

Answer: c

Explanation: The program contains a compile-time error, possibly due to a syntax issue or invalid operation caught by the compiler before execution.


Q2. What is the output of the following program?
a. 1 3
b. 1 2 3 4
c. Runtime error
d. 1 2

Answer: a

Explanation: The logic of the program ensures only 1 and 3 are printed, skipping or breaking on other numbers. Often due to loop conditions or control statements like continue.


Q3. For the program given below, what will be the output after its execution?
a. 0
b. true
c. 1
d. false

Answer: c

Explanation: The variable being printed is likely an integer and is set or incremented to 1 within the code logic.


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

Explanation: The constructor Thread(Runnable a, String str) creates a thread with a target Runnable and a name, which is valid in Java.


Q5. What is the output of the following program?
a. Compiler Error
b. “Running”
c. Runtime Exception
d. No output, but no error

Answer: b

Explanation: The code likely prints the string "Running" from within a valid method, possibly run().


Q6. How many threads does the following program run on?
a. 0
b. 1
c. 2
d. 3

Answer: c

Explanation: One is the main thread and another thread is explicitly started in the code, totaling two threads.


Q7. In the following java program, what is the NAME of the thread?
a. thread
b. main
c. system
d. None of the above

Answer: b

Explanation: By default, the name of the initial thread executing a Java program is "main".


Q8. Which of the following line(s) of code is suitable to START a thread at #1?
a. Thread t = new Thread(Nptel);
b. Thread t = new Thread(Nptel);
  t.start();
c. Nptel run = new Nptel();
  Thread t = new Thread(run);
  t.start();
d. Thread t = new Thread();
  Nptel.run();

Answer: c

Explanation: You need to create an instance of a class that implements Runnable, pass it to a Thread, and then call start() to begin execution.


Q9. What is the name of the priority of this Thread in this program?
a. 1
b. 4
c. 0
d. 5

Answer: d

Explanation: The default priority of a thread in Java is 5.


Q10. What does I/O stand for in Java?
a. Input/Output
b. Inheritance/Overriding
c. Integer/Object
d. Iteration/Observation

Answer: a

Explanation: I/O stands for Input/Output in Java, referring to data read/write operations like using System.in, System.out, or file streams.