NPTEL Programming in Java Week 5 Assignment Answeers 2024
1. Which exception will be thrown by parseInt() method in Java?
a. IntegerOutOfBoundException
b. IntegerFormatException
c. ArithmeticException
d. NumberFormatException
Answer :- For Answers Click Here
2. What will be the output of the following program?
a.
b.
c.
d. Compilation error
Answer :- For Answers Click Here
3. What will be the output of the following code?
a. 4
b. 6
c. 2
d. 8
Answer :- For Answers Click Here
4. A method that potentially generates a checked exception must include this keyword in its method signature:
a. throw
b. extend
c. throws
d. extends
Answer :-
5. Which of the following statements is true about Java’s finally block?
a. The finally block is only executed if an exception is thrown in the try block
b. The finally block is only executed if an exception is thrown in the catch block
c. The finally block is only executed if an exception is not thrown in the try or catch block
d. The finally block is executed regardless of whether an exception is thrown in the try or catch block
Answer :-
6. Which of the following statements is true about exception handling in Java:
a. A try block can have many catch blocks but only one finally block
b. A try block can have many catch blocks and many finally blocks
c. A try block must have one finally block for each catch block
d. A try block must have at least one catch block to have a finally block
Answer :- For Answers Click Here
7. What will be the output of the following program?
a. Hello
b. World
c. HelloWOrld
d. WorldWorld
Answer :-
8. What will be the output of the following Java code?
a. Hello
b. World
c. HelloWOrld
d. Compilation Error
Answer :-
9. What will be the output of the following Java program?
a. 0 0
b. 2 2
c. 4 1
d. 1 4
Answer :-
10. Which of the following exceptions is not a subclass of the RuntimeException class?
a. NullPointerException
b. ArrayIndexOutOfBoundsException
c. IOException
d. ArithmeticException
Answer :- For Answers Click Here