NPTEL Programming In Java Week 5 Assignment Answers 2024

Join Our WhatsApp Group Join Now
Join Us On Telegram Join Now

Q1. Which of the following is an incorrect statement about interfaces?
a. Interfaces specifies what class must do but not how it does.
b. Interfaces are specified public if they are to be accessed by any code in the program.
c. All variables in interface are implicitly final and static.
d. All variables are static and methods are public if interface is defined public.

Answer:- For Answer Click Here

Q2. How do you access a static method of an interface?
a. Using the interface name
b. Using the method name directly
c. Through an object of the interface
d. Through an implementation class

Answer:- 

Q3. What is the output of the below Java program with an Interface?

NPTEL Programming In Java Week 5 Assignment Answers 2024

a. 1000
b. 2000
c. Compiler error
d. None of the above

Answer:- For Answer Click Here

Q4. What happens when we access the same variable defined in two interfaces implemented by the same class?
a. Compilation failure
b. Runtime Exception
c. The JVM is not able to identify the correct variable
d. The interfaceName.variableName needs to be defined

Answer:- 

Q5. Predict the output of following Java program

NPTEL Programming In Java Week 5 Assignment Answers 2024

a. Got the Test Exception
Inside finally block
b. Got the Test Exception
c. Inside finally block
d. Compiler Error

Answer:- For Answer Click Here

Q6. What happens if an exception is not caught in the catch block?
a. The finally block handles it
b. The exception is ignored
c. The exception is thrown to the caller method
d. The program terminates immediately

Answer:- 

Q7. What will be the output of the following Java program?

NPTEL Programming In Java Week 5 Assignment Answers 2024

a. Hello
b. World
c. HelloWorld
d. Hello World

Answer:- For Answer Click Here

Q8. What is the output of the below Java code with Exceptions?

NPTEL Programming In Java Week 5 Assignment Answers 2024

a. Index 4 out of bounds for length 3
b. Index 4 out of bounds for length 3 Some exception
c. Some exception
d. No exception occurs

Answer:- For Answer Click Here

Q9. What is the output of the Java code with FINALLY block and RETURN statement?

NPTEL Programming In Java Week 5 Assignment Answers 2024

a. inside TRY
b. inside TRY
inside FINALLY
c. inside FINALLY
d. Compiler error

Answer:- 

Q10. What is the purpose of the finally block in Java exception handling?
a. To handle an exception
b. To catch an exception
c. To clean up resources after a try block
d. None of the above

Answer:- For Answer Click Here