The program given below is will help you understanding of exception handling of java and also helpful for SCJP examination.
The program given below is will help you understanding of exception handling of java and also helpful for SCJP examination.1. import java.io.*;
2. public class Example4 {
3. public static void main(String[] args) {
4. Example4 e4 = new Example4();
5. try{
6. e4.check();}
7. catch(IOException e){}}
8. void check() throws IOException{
9. System.out.println("Inside check() method of Class ");
10. throw new IOException();}}
11. class Subexample4 extends Example4 {
12. void check() {
13. System.out.println("Inside check() Method of Subclass");
14. }}
What will be the output of the following code snippet :
(1) Above program will throw exception & will not run.
(2).Inside check() method of class
(3) Inside check() method of Subclass
(4)Inside check() method of class
Inside check() method of Subclass.
(2)
Explanation :
Because the "e4"object is the member of the main class , therefore it can call only the methods of the main class.