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.