Menu
Topics Index
...
`

Exception Handling throws keyword


If you need explanation Read this topic If you need explanation Read this topic

If you need Answer Take test on this topic

Exception Handling throws keyword
What will be the output of the following program?
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        Except e = new Except();
        e.disp();
        Except1 e1 = new Except1();
        e1.disp();
        Trial t = new Trial();
        t.disp();
    }
}
class Except {
    public void disp() throws EOFException, FileNotFoundException {
        System.out.println("It is a super class");
    }
}
class Except1 extends Except {
    public void disp() throws FileNotFoundException {
        System.out.println("It is a sub class named except1");
    }
}
class Trial extends Except {
    public void disp() throws IOException {
        System.out.println("It is a sub class named trial");
    }
}

A. It is a super class
It is a sub class named except1
It is a sub class named trial
B. It is a super class
It is a super class
It is a sub class named except1
It is a super class
It is a sub class named trial
C. Some other output
D. Compilation Error or Runtime Error
Topic: Java Throw Keyword - Java Throws Keyword Exception Handling Syntax In Java Programming

If you need explanation Read this topic If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

D,, IOexception is not subclass of any EOF and FileNotFounf Exception

Posted by Raju VarshnEy    2014-10-29 12:35:39


Ans is D..Here we have 4 classes..here Except is the parent class for the Except1 and trial classes..
throws--> is key word in java which is ued to indicate the system that Exceptions raied in this method defination wil not handled here..the caller of the method should handle this

here in class Except we have method named with disp() it is throwing EOFException,FileNotFoundException..

in the Except1  class we override the disp() here this method throwing FileNotFoundException..

when we override the method from the Parent class the child class method must specify at throws the sam as its Parent class (or) we should specify the it;s child classes...here FileNotFoundException is not child of EOFException so that compiler wil raise an error

Posted by Uday Kumar    2014-10-29 16:44:47


d.

Posted by Shubham Bansal    2014-10-29 17:08:36


This dose is now closed and the winners are Raju VarshnEy,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Vikas Tiyagi. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-31 06:14:22


© meritcampus 2019

All Rights Reserved.

Open In App