Q) Direct subclass of Throwable in Java
- Exception
- Error
- Both A & C
- None
Answer: 3
Q) un-checked(runtime) exception in java is/are
- ArrayIndexOutOfBoundsException
- ArithmeticException
- NullPointerException
- All
Answer: 4
Q) 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
Answer: 3
During compile time, itself File not found exception will occur. So, to avoid it, we need to wrap above statement with try catch block or with throws exception e.g.
public static void main(String[] args) throws FileNotFoundException {
FileReader file = new FileReader("test.txt");
}
OR
public static void main(String[] args) {
try {
FileReader file = new FileReader("test.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Q) 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
Answer: 3
In java exception handling, for each try block there can be zero or more catch blocks, but only one finally block.
Q) 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
Answer: 3