Java Exception Handling Test 3 - Java Question and Answers
Finish Quiz
0 of 17 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
Information
Java Exception Handling Test 3 – Java Question and Answers.ย Free Java Exception Handlingย Quiz. Take our Freeย JDBCย Onlineย Quiz – Learningย JDBCย in simple and easy steps using this beginner’s Online Test. Take free online Test Quiz 3. Java Exception Handlingย Test Quiz 3ย Question and Answers 3017. Java online Test Quiz 3. Java Exception Handlingย Quiz 3ย Free Mock Testย 3017.ย Java Exception Handlingย Test Quiz 3ย Question and Answers in PDF.ย The Java online mock test paper is free for all students.ย Java Exception Handlingย Testย is very useful for exam preparation and getting for Rank. Java Exception Handlingย Test Quiz 3ย Question and Answers in English. Java Exception Handlingย Mock test forย ย topic via Exception Handlingย Mode.ย Here we are providingย Java Exception Handlingย Mock Test in Englishย Now Test your self for โJava Exception Handlingย Testย in Englishโ Exam by using below quizโฆ
This paper has 20ย questions.
Time allowed is 25 minutes.
The Java Exception Handlingย Mock Test ย is Very helpful for all students.ย Now Scroll down below n click on โStart Quizโ or โStart Testโ andย Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 17 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- Answered
- Review
-
Question 1 of 17
1. Question
What will be the output?
- publicย classย Test6{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[])ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย try{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย throwย newย Exception();
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย finally{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Noย Error”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- }
Choose the one below:
Correct
finally block is executed everytime. The only way to escape finally is to call System.exit().
Hence the above code snippet will print “No Error” followed by java.lang.Exception.
Incorrect
finally block is executed everytime. The only way to escape finally is to call System.exit().
Hence the above code snippet will print “No Error” followed by java.lang.Exception.
-
Question 2 of 17
2. Question
What will be the output?
- publicย classย Test9ย extendsย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[])ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Test9ย tย =ย newย Test9();
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- }
- classย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย A()ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Aย Class”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- }
Choose the one below:
Correct
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception).
In the above code snippet the default constructor neither catch the exception thrown by super class default constructor nor declare that default constructor throws exception. Hence it will give compile time error.
Incorrect
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception).
In the above code snippet the default constructor neither catch the exception thrown by super class default constructor nor declare that default constructor throws exception. Hence it will give compile time error.
-
Question 3 of 17
3. Question
What will be the output?
- publicย classย Test9ย extendsย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Test9()ย throwsย IOException{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Test9ย Class”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[])ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Test9ย tย =ย newย Test9();
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย classย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย A()ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Aย Class”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย }
Choose the one below:
Correct
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception). In the above code snippet Test9() throws exception which is subclass of Exception class and its superclass constructor is throwing Exception exception.
Hence the above code will give compile time error.
Incorrect
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception). In the above code snippet Test9() throws exception which is subclass of Exception class and its superclass constructor is throwing Exception exception.
Hence the above code will give compile time error.
-
Question 4 of 17
4. Question
What will be the output?
- publicย classย Test10ย extendsย A{
- ย ย ย ย ย ย ย ย Test10()throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Test10ย Class”);
- ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[])ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย Test10ย tย =ย newย Test10();
- ย ย ย ย ย ย ย ย }
- ย ย ย }
- ย ย ย classย A{
- ย ย ย ย ย ย ย ย A()ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Aย Class”);
- ย ย ย ย ย ย ย ย }
- ย ย ย }
Choose the one below:
Correct
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception). The above code snippet handles the exception properly in subclass constructor resulting successful compilation and results A Class Test 10 Class on the console.
Incorrect
The constructor must either catch the exception thrown by the superclass’s constructor or it must declare that it throws that same exception (or a superclass of that exception). The above code snippet handles the exception properly in subclass constructor resulting successful compilation and results A Class Test 10 Class on the console.
-
Question 5 of 17
5. Question
What will be the output?
- publicย classย Mainย extendsย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Main()ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Mainย Class”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย publicย staticย voidย main(Stringย args[])ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย Mainย tย =ย newย Main();
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย classย A{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย A()ย throwsย Exception{
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“Aย Class”);
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย }
Choose the one below:
Correct
In the above code snippet Main t = new Main(); invokes Main() constructor which inturn calls super() as first statement and invokes A() constructor; Resulting A class Main class on the console.
Incorrect
In the above code snippet Main t = new Main(); invokes Main() constructor which inturn calls super() as first statement and invokes A() constructor; Resulting A class Main class on the console.
-
Question 6 of 17
6. Question
Which of the following lists exception types from MOST specific to LEAST specific?
Correct
The Exception Hierarchy in Java can be represented as:-
Hence from the above options it is clear that ArithmeticException, RunTimeException is the correction option.Note:- Moving Top to down in the hierarchy makes exception class more specific whereas down to top makes class more generialize.
Incorrect
The Exception Hierarchy in Java can be represented as:-
Hence from the above options it is clear that ArithmeticException, RunTimeException is the correction option.Note:- Moving Top to down in the hierarchy makes exception class more specific whereas down to top makes class more generialize.
-
Question 7 of 17
7. Question
On occurrence of which of the following is it possible for a program to recover?
Correct
An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions and it can be recovered whereas recovery from an Error is not possible & the program should be allowed to terminate. Examples include OutOfMemoryError, StackOverflowError, etc.
Incorrect
An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions and it can be recovered whereas recovery from an Error is not possible & the program should be allowed to terminate. Examples include OutOfMemoryError, StackOverflowError, etc.
-
Question 8 of 17
8. Question
What will be the output?
Choose the one below:
- publicย classย Test4{
- ย ย publicย voidย method(){
- ย ย ย ย ย System.out.println(“”Called“”);
- ย ย }
- ย ย publicย staticย voidย main(String[]ย args){
- ย ย ย ย ย Test4ย t4ย =ย null;
- ย ย ย ย ย t4.method();
- ย ย }
- }
Correct
In the above code snippet refernce variable t4 has not been initialized and when t4.method() will be called it will give NullPointerException at runtime.
Incorrect
In the above code snippet refernce variable t4 has not been initialized and when t4.method() will be called it will give NullPointerException at runtime.
-
Question 9 of 17
9. Question
Exceptions can be caught or rethrown to a calling method.
Correct
In Java exception can be caugth or rethrown from catch block by adding some extra information(Custom Exception) as per requirement.
For example:-
ย ย ย try
ย ย ย {
ย ย ย ย ย ย //Your Code Here
ย ย ย }
ย ย ย catch (Exception e)
ย ย ย {
ย ย ย ย ย ย throw new YourOwnException(e);
ย ย ย }Incorrect
In Java exception can be caugth or rethrown from catch block by adding some extra information(Custom Exception) as per requirement.
For example:-
ย ย ย try
ย ย ย {
ย ย ย ย ย ย //Your Code Here
ย ย ย }
ย ย ย catch (Exception e)
ย ย ย {
ย ย ย ย ย ย throw new YourOwnException(e);
ย ย ย } -
Question 10 of 17
10. Question
- classย Aย {
- ย ย ย ย publicย staticย voidย mainย (String[]ย args)ย {
- ย ย ย ย ย ย ย ย Objectย errorย =ย newย Error();
- ย ย ย ย ย ย ย ย Objectย runtimeExceptionย =ย newย RuntimeException();
- ย ย ย ย ย ย ย ย ย System.out.print((errorย instanceofย Exception)ย +ย “,”);
- ย ย ย ย ย ย ย ย ย System.out.print(runtimeExceptionย instanceofย Exception);
- }
- }
What is the result of attempting to compile and run the program?
Correct
instanceof operator checks whether the object is of specified type i.e class or subclass or interface.
Hence output of above code snippet is: “false,true“
Incorrect
instanceof operator checks whether the object is of specified type i.e class or subclass or interface.
Hence output of above code snippet is: “false,true“
-
Question 11 of 17
11. Question
Given the following:
- publicย classย TestDivideย {
- ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย intย value=0;
- ย ย ย ย ย ย tryย {
- ย ย ย ย ย ย ย ย ย ย ย ย intย resultย =ย 10/value;
- ย ย ย ย ย ย }ย finallyย {
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.println(“f”);
- ย ย ย ย ย ย }
- ย ย ย ย ย }
- ย }
What is the result ?
Correct
The above code will give ArithmeticException when line 5 is executed and then finally block will executed which will print “f” followed by exception on console.
Incorrect
The above code will give ArithmeticException when line 5 is executed and then finally block will executed which will print “f” followed by exception on console.
-
Question 12 of 17
12. Question
Given:
- publicย classย TestExceptionย {
- ย ย ย publicย staticย voidย main(String…ย args)ย {
- ย ย ย ย ย ย ย ย ย tryย {
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย //ย someย pieceย ofย code
- ย ย ย ย ย ย ย ย }ย catchย (NullPointerExceptionย e1)ย {
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“n”);
- ย ย ย ย ย ย ย ย }ย catchย (RuntimeExceptionย e2)ย {
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“r”);
- ย ย ย ย ย ย ย ย }ย finallyย {
- ย ย ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“f”);
- ย ย ย }
- ย ย }
- }
What is the output if NullPointerException occurs when executing the code in the try block?
Correct
If NullPointerException occurs it will be caught by catch block at line 5 and then finally block will be executed resulting “nf” on cconsole.
Incorrect
If NullPointerException occurs it will be caught by catch block at line 5 and then finally block will be executed resulting “nf” on cconsole.
-
Question 13 of 17
13. Question
Which exception occurs when you try to parse invalid integer using parseInt() function?
Correct
If parseInt() method gets illegal data which cannot be parsed to Integer it throws NumberFormatException exception.
Incorrect
If parseInt() method gets illegal data which cannot be parsed to Integer it throws NumberFormatException exception.
-
Question 14 of 17
14. Question
What is the output of the given console application?
- publicย classย Test31ย {
- ย ย ย ย ย ย publicย staticย voidย main(String[]ย args)ย {
- ย ย ย ย ย ย ย ย ย test();
- ย ย ย ย ย }
- ย ย ย ย ย publicย staticย voidย test()ย {
- ย ย ย ย ย ย ย ย ย tryย {
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“-try”);
- ย ย ย ย ย ย ย ย ย ย ย ย return;
- ย ย ย ย ย ย ย ย ย }ย catchย (Exceptionย e)ย {
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“-catch”);
- ย ย ย ย ย ย ย ย ย }ย finallyย {
- ย ย ย ย ย ย ย ย ย ย ย ย System.out.print(“-finally”);
- ย ย ย ย ย ย ย ย ย }
- ย ย ย ย }
- }
Correct
finally block is executed everytime. The only way to escape finally is to call System.exit(). Hence when above code snippet is executed first try block is executed and then finally block gets executed resulting -try-finally on the console.
Incorrect
finally block is executed everytime. The only way to escape finally is to call System.exit(). Hence when above code snippet is executed first try block is executed and then finally block gets executed resulting -try-finally on the console.
-
Question 15 of 17
15. Question
What exception might a wait() method throw?
Correct
wait() method may throw checked exception i.e. InterruptedException. Hence any method using wait() method should surround it with try-catch block or should declare throws InterruptedException in method signature.
Incorrect
wait() method may throw checked exception i.e. InterruptedException. Hence any method using wait() method should surround it with try-catch block or should declare throws InterruptedException in method signature.
-
Question 16 of 17
16. Question
Which of the following statements about an overridden method is false?
Correct
An overridden method can declare to throw less checked exceptions that the base class method.
An overriding method can throw any unchecked exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw those checked exceptions, which have less scope than the exception(s) declared in the overridden method.
Incorrect
An overridden method can declare to throw less checked exceptions that the base class method.
An overriding method can throw any unchecked exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw those checked exceptions, which have less scope than the exception(s) declared in the overridden method.
-
Question 17 of 17
17. Question
What will be the output of the following code snippet?
- classย Exception{
- ย ย ย ย publicย staticย voidย main(Stringย args[]){
- ย ย ย ย ย ย ย ย try{
- ย ย ย ย ย ย ย ย ย ย ย ย intย a[]=newย int[1];
- ย ย ย ย ย ย ย ย ย ย ย ย a[1]=30/0;
- ย ย ย ย ย ย ย ย ย ย ย ย a[2]=50;
- ย ย ย ย ย ย ย ย }
- ย ย ย ย ย ย ย ย catch(ArithmeticExceptionย e)
- {System.out.println(“Exception1”);}
- ย ย ย ย ย ย ย ย catch(ArrayIndexOutOfBoundsExceptionย e)
- {System.out.println(ย “Exception2”);}
- ย ย ย ย ย ย ย ย System.out.println(“rest”);
- ย ย ย ย }
- }
Correct
The output of above code snippet will be
Exception1
rest
AS we know first the evaluation is done and then assignment happens. First 30/0 is evaluated and it throws ArithmeticException.
Incorrect
The output of above code snippet will be
Exception1
rest
AS we know first the evaluation is done and then assignment happens. First 30/0 is evaluated and it throws ArithmeticException.