Font size
Worksheets22BCA6B-Quiz-Exception Handling
Total questions: 98
Worksheet time: 55mins
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throw
Exception
Error
Bug
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
Which of the following exceptions class belongs to Checked Exception
ArithmeticException
ClassNotFoundExceptions
ClassCastException
ArrayIndexOutOfBoundsException
class IT
{
static public void main(String...args)
{
int k=Integer.parseInt(args[0]);
System.out.println(k);
}
}
if args[0]="gec" then what type of exception is thrown by the above program.
NumberFormatException
NullPointerException
ArrayIndexOutOfBoundsException
InvalidStringException
What are immediate child classes of Throwable
Error
Exception
CheckedException
UnCheckedException
class Add
{
static public void main(String...args)
{
try
{
int a=10,b=0;
System.out.println(a/b);
}
catch(ArithmeticException ex)
{
System.out.println("Error:");
}
}
}
Above program throws an exception at
Runtime
Compile time
either compile time or run time
None of these
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
class IT
{
static public void main(String...args)
{
String s=null;
System.out.println("length is:"+s.length());
}
}
It throws NullPointerException
it throws IOException
It throws StringExeption
output is 0
Nested try and Multi-try both are same
It is True
It is False
A java program contains any number of try and catch blocks
True
False
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
What is the output of this program?
0
1
2
Compilation Error
What is the output of this program?
2 2
3 3
2 3
3 2
What is the output of this program?
1 2
2 1
Runtime Error
Compilation Error
what is the output?
Base
Derived
compile time error
run-time error
Output of following Java program?
Base
Derived
Derived
Base
Base
Derived
Base
Derived
Base
Compiler Error
Which of the following is true about inheritance in Java?
1, 2 and 4
Only 1 and 2
1, 2 and 3
2, 3 and 4
output of the program
Base::show() called
Compiler Error
Derived::show() called
None
output of the program
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
Output of following Java Program?
Derived::show() called
compile time error
Base::show() called
runtime error
Predict the output of following Java program?
0
garbage value
compile time error
runtime error
Predict the output of following Java program
garbage value
0
compile time error
runtime error
output of the program
Compile error
values of obj1:
a = 11 b = 21
values of obj2:
a = 11 b = 21
values of obj1:
a = 11 b = 21
values of obj2:
a = 10 b = 20
values of obj1:
a = 11 b = 20
values of obj2:
a = 10 b = 21
runtime error
Predict the output of the following program.
Compilation error
Inside First
Inside First
Inside First
Inside Second
Runtime error
What is the output of the following JAVA program ?
dogood : dogoodgood
dogood : gooddogood
dogood : dodogood
dogood : dogood
Predict the output?
20
0
Compiler Error
none
Which of the following is/are true about constructors in Java?
1
1,2
1, 2, 4
1,2,3 & 4
output of the program
inside static block
a = 4
inside constructor
a = 11
Compiler Error
Run Time Error
inside static block
a = 4
inside constructor
a = 5
inside static block
a = 10
inside constructor
a = 11
What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
Method overloading
Method overriding
Method hiding
None of the mentioned
What is the output of this program?
2
3
7
compile time error
what is the output
9.0 9.0
9 9
compile time error
none
I am a Person
I am a Student
I am a Person I am a Student
I am a Student I am a Person
Determine the output?
r1 r4 pre b1 b2 post
pre r1 r4 b1 b2 r2 r3 post
r1 r4 pre b1 b2 r3 r2 post
r1 r4 pre b1 b2 post r3 r2
Determine the output?
one
one two
one two 20
20
one 20
Read the statement
Declare the method with the keyword public.
Declare the method with the keyword private.
Declare the method with the keyword protected.
Do not declare the method with any accessibility modifiers.
Declare the method with the keyword public and private.
Read the statement
Only (III)
(II) and (III)
(I) and (II)
Only (I)
(I), (II) and (III)
Read the Program
1 and 2
2 and 4
3 and 4
1 and 3
A Package is the collection of
classes
interfaces
classes and interfaces
editing tools
editing tools and interfaces
which of these lines will give compile time error?
1
2
3
4
None of these
The class at the top of the exception hierarchy is
ArithmeticException
Throwable
Object
Exception
in which package Exception class is available?
java.util
java.file
java.io
java.lang
java.net
Exception generated in try block will caught in...... block
catch
throw
throws
finally
which keyword is used to explicitly throw an exception?
try
throwing
catch
throw
throws
which exception will through by decided by zero?
NumberFormatException
ArithmeticException
NullPointerException
None of these
What happen in case of multiple catch blocks
Either super or subclass can be caught first.
The superclass exception must be caught first.
The superclass exception cannot caught first.
None of these
What will be the output?
inCatchBlock
inCatchBlock inFinallyBlock
inFinallyBlock
The program will return without printing anything
Given the following piece of code
1 and 4
2 and 3
2 and 4
3 and 4
1 and 2
what is the output?
There is a NullPointerException.
There is a NullPointerException. Everything went fine.
There is a NullPointerException. There is an Exception.
This code will not compile, because in Java there are no pointers.
what is the output?
One
Two
One Two
Compilation Error
Read the statement
A and D
A and B
A and C
B and C
What is the output?
"doCdoBdoA" is printed
"doAdoBdoC" is printed
"doBdoAerror" is printed
"error" is printed
nothing is printed
what will be the result if NullPointerException occurs at line 2.
1
3
2 3
1 3
1 2 3
What is the output?
"one" is printed.
"null pointer exception" is printed.
"exception" is printed.
Compilation fails saying NullPointerException has already been caught.
None of these
what is the output after compilation of this code?
Overridden: hello (String, Integer[])
Compilation fails
hello (String, Integer[])
None of these
Is this program create a new file with a.txt
true
false
None of these
Compilation Error
what is the output?
Value-A
Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName()
Name-B
Compilation succeed but no output
None of these
What is the output of this program?
Prints out: Exception
Prints out: Exception Finally
Compile with error
Prints out: Finally
None of these
What is the output?
3
3.5
Compilation Error
None of these
what exception could be handled by catch block
IllegalStateException
ClassCastException
NumberFormatException
ArrayIndexOutOfBoundsException
None of these
What is the output?
Got the Exception 10
Got the Exception 0
Compiler Error
none of the above
What is the output?
Got the Test Exception
Inside finally block
Got the Test Exception
Inside finally block
Compiler Error
What is the output?
Caught base class exception
Caught derived class exception
Compiler Error because derived is not throwable
Compiler Error because base class exception is caught before derived class
What is the output?
Compile error
Divide by zero error
a = 0
Divide by zero error
inside the finally block
a = 0
inside the finally block
What is the output?
error occurred
End of the program
Not Eligible for voting
End of the program
Eligible for voting
End of the program
none
What is the purpose of a try-catch block in Java?
To improve code readability.
To optimize performance of the program.
To define variables in a method.
To handle exceptions and prevent program crashes.
How do you throw an exception in Java?
Use 'throw new Error("message");' instead of Exception.
Throw an exception using 'throw Exception();' with no message.
Use 'throw new Exception("message");' to throw an exception in Java.
Use 'throw Exception("message");' without 'new'.
What is the difference between checked and unchecked exceptions?
Checked exceptions are always runtime errors.
Checked exceptions require handling, while unchecked exceptions do not.
Both checked and unchecked exceptions require handling.
Unchecked exceptions must be declared in the method signature.
When is the finally block executed in Java?
The finally block is executed after the try and catch blocks, regardless of exceptions.
The finally block is executed before the try block.
The finally block is executed only if an exception occurs.
The finally block is executed only if there is no catch block.
Can you nest try-catch blocks in Java?
No, try-catch blocks cannot be nested in Java.
Yes, you can nest try-catch blocks in Java.
You can only have one try block in Java.
Catch blocks must always follow a try block directly without nesting.
What happens if an exception is not caught?
The program will run faster.
The program may terminate unexpectedly.
The exception will be logged automatically.
The program will continue to run without issues.
What is the syntax for a try-catch block?
try { /* code */ } catch { /* handle error */ }
try { /* code */ } catch (ExceptionType e) { /* handle exception */ }
try { /* code */ } finally { /* cleanup */ }
try (/* code */) { /* handle exception */ }
How do you create a custom exception in Java?
public class MyCustomException extends Exception { public MyCustomException(String message) { super(message); } public MyCustomException(String message, Throwable cause) { super(message, cause); }}
public class MyCustomException extends RuntimeException { }
public class MyCustomException { public MyCustomException() { } }
public class MyCustomException implements Exception { }
What is the role of the throw keyword?
The throw keyword is used to define a function.
The throw keyword is used to raise an exception.
The throw keyword is used to catch exceptions.
The throw keyword is used to declare variables.
What are some common checked exceptions in Java?
NullPointerException
ArrayIndexOutOfBoundsException
IllegalArgumentException
IOException, SQLException, ClassNotFoundException
What are some examples of unchecked exceptions?
IOException
SQLException
FileNotFoundException
Examples of unchecked exceptions include NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, and IllegalArgumentException.
How can you handle multiple exceptions in a single catch block?
Ignore exceptions and let them propagate up the call stack.
Use a single catch block with multiple exception types separated by a pipe (|).
Only catch the most specific exception type.
Use multiple catch blocks for each exception type.
What is the significance of the finally block?
The 'finally' block can be used to declare variables in a method.
The 'finally' block is only executed if no exceptions occur.
The 'finally' block is used to define a method in a class.
The 'finally' block ensures that specific code runs after try/catch, regardless of exceptions.
Can you have a try block without a catch block?
Yes, a try block can exist without any additional blocks.
No, a try block is invalid without a catch or finally block.
Yes, you can have a try block without a catch block if a finally block is present.
No, a try block must always have a catch block.
What is the difference between throw and throws in Java?
'throw' is used for declaring exceptions in method signatures, 'throws' is for throwing exceptions.
'throw' is for throwing exceptions, 'throws' is for declaring exceptions in method signatures.
'throw' can only be used in static methods, while 'throws' can be used anywhere.
'throw' is a keyword for handling errors, 'throws' is for logging exceptions.
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throw
Exception
Error
Bug
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
What will it print?
1
2
3
30
1
2
30
1
2
3
11
1
2
11
What will this program print?
Nothing, there is an error
There was a ValueError, please try again
num1num2
num2num1
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails.
The code runs with no output
An exception is thrown at runtime.
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
none
Choose the CORRECT mechanism of exception handling.
try block --> catch block --> finally block
try block --> catch block --> throws exception
try block --> catch block --> finally --> throws exception
try block --> throws exception--> catch block --> finally block
What is the output?
The code will lead to a compilation error as declaration of the display method has been provided in two interface.
The code will lead to a compilation error due to public modifier while declaring the display method.
The code will compile and execute successfully showing the output Welcome to Examveda.
The code will lead to a compilation error as the display method is not declared as abstract.
None of these
Exception is a class/interface/abstract class/other?
Class
Interface
Abstract class
Other
1. class main_class
2. {
3. public static void main(String args[])
4. {
5. int y = 10;
6. if (y == 10)
7. {
8. int y = 11;
9. System.out.println(y);
10. }
11. }
12. }
Compilation error
10
11
Run time error
