NEW
Font size
Worksheetsjava-ExceptionHandling-vlits
Total questions: 37
Worksheet time: 2hrs 43mins
When does Exceptions in Java arises in code sequence?
Run Time
Compilation Time
Can Occur Any Time
None of the mentioned
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
Which of these keywords must be used to monitor for exceptions?
try
finally
throw
catch
Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
try
finally
throw
catch
Which of these keywords is used to manually throw an exception?
try
finally
throw
catch
What is the output of the program?
class exception_handling{
public static void main(String args[]){
try{
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e){ System.out.print("World");
}
}
}
Hello
World
HelloWorld
Hello World
What is the output of the following program?
class exception_handling{
public static void main(String args[]){
try{
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
}
catch(ArithmeticException e){
System.out.print("B");
}
}
}
A
B
Compilation Error
Run Time Error
What is the output of this program?
class exception_handling{
public static void main(String args[]){
try{
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
}
catch(ArithmeticException e){
System.out.print("B");
}
finally{
System.out.print("C");
}
}
}
A
B
AC
BC
What is the output of the following program?
class exception_handling{
public static void main(String args[]){
try{
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
sum = (sum / i);
}
catch(ArithmeticException e){
System.out.print("0");
}
System.out.print(sum);
}
}
0
05
Compilation Error
Runtime Error
The class at the top of exception class hierarchy is .................
ArithmeticException
Throwable
Object
Exception
In which of the following package Exception class exist?
java.util
java.file
java.io
java.lang
java.net
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
try{
File f = new File("a.txt");
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt ?
true
false
Compilation Error
None of these
Which of the below statement is/are true about Error?
A. An Error is a subclass of Throwable.
B. An Error is a subclass of Exception.
C. Error indicates serious problems that a reasonable application should not try to catch.
D. An Error is a subclass of IOException.
A and D
A and B
A and C
B and C
B and D
Given the code. What is the result when this program is executed?
public class Test{
static int x[];
static{
x[0] = 1;
}
public static void main(String args[]){
}
}
ArrayIndexOutOfBoundsException is thrown
ExceptionInInitializerError is thrown
IllegalStateException is thrown
StackOverflowException is thrown
None of these
Which of the following are the most common run-time errors in Java programming.
i) Missing semicolons
ii) Dividing an integer by zero
iii) Converting invalid string to number
iv) Bad reference of objects
i and ii only
ii and iii only
iii and iv only
i and iv only
Which of the following are the most common compile time errors in Java programming.
i) Missing semicolons
ii) Use of undeclared variables
iii) Attempting to use a negative size for an array
iv) Bad reference of objects
i, ii and iii only
ii, iii and iv only
i, ii and iv only
All i, ii, iii and iv
The unexpected situations that may occur during program execution are
i) Running out of memory
ii) Resource allocation errors
iii) Inability to find a file
iv) Problems in network
i, ii and iii only
B)
C)
D)
ii, iii and iv only
i, ii and iv only
All i, ii, iii and iv
……………………….. exception is caused when an applet tries to perform an action not allowed by the browser’s security setting.
Throwable
Restricted
Security
ArrayIndexOutofBounds
State whether the following statements are True or False.
i) A catch can have comma-separated multiple arguments.
ii) Throwing an Exception always causes program termination.
True, False
False, True
True, True
False, False
Which is valid about java.lang.Exceptions?
The class Exception and all its subclasses that are not also subclasses of RuntimeException are checked exceptions.
The class Error and all its subclasses are unchecked exceptions.
The class RuntimeException and all its subclasses are unchecked exceptions.
All.
FileInputStream implements which interface for closing file automatically in java7?
java.lang.AutoClose
java.lang.CloseAutomatically
java.lang.AutoCloseable
java.lang.Closeable
Types of exceptions in Java programming are
Checked exception
unchecked exception
Both A & B
None
Checked exception caught at
compile time
run time
Both at compile and run time
None
Unchecked exception caught at
compile time
run time
Both at compile and run time
None
Direct subclass of Throwable in Java
Exception
Error
Both A & C
None
un-checked(runtime) exception in java is/are
ArrayIndexOutOfBoundsException
ArithmeticException
NullPointerException
All
In below java program, which exception will occur?
public static void main(String[] args) {
FileReader file = new FileReader("test.txt");
}
NullPointerException at compile time
NullPointerException at run time
FileNotFoundException at compiler time
FileNotFoundException at runtime
Incorrect statement(s) about finally block in java exception
Finally block always follow try catch block
finally block always executes whether exception is handled or not.
There can be multiple finally blocks followed by try catch block.
All are correct
True statement(s) about try catch block
It is mandatory to have catch block with every try block
There must be only one catch block followed by try block
There can be multiple catch block followed by try block.
All
True statement about throws and throw is/are
Throws is used with the method signature.
Throw is used within the method.
using throws multiple exceptions can be declared
All are correct.
When the JVM runs out of memory, which exception will be thrown?
MemoryBoundException
OutOfMemoryError
OutOfRangeException
NullReferenceException
When a program is stopped due to lack of memory then -------------------------- is thrown.
OutOfMemoryError
OutOfRangeException
NullReferenceException
MemoryBoundException
Which exception is thrown by read() method ?
Exception
FileNotFoundException
ReadException
IOException
Attempting to access a character that is outside the bounds of a StringBuffer results in a
ArrayIndexOutOfBoundsException
StringOverFlowException
StringException
StringIndexOutOfBoundsException
Exception and Error are immediate subclasses of a class called
Object
Throwable
AWT
Panel
URL throws an exception called
IllegalURLException
URLException
MalformedHostException
MalformedURLException
