Welcome Guest | Sign in | Register
Exceptions - Discussion Page For Q.2629 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Exceptions > Questions and Answers

Q: class A{
void display() throws IOException,FileNotFoundException {
System.out.println(“class A”); }
}
class B extends A {
void display() throws ClassNotFoundException, SQLException {
System.out.println(“class B”); }
}
class Test {
Public static void main(String args[]){
B b=new B();
b.display(); 
}
}
Output?
A. class A B. class B
C. class A, class B D. compile time error

Answer and Explanation

Answer:compile time error

Explanation:
In the above program class A is super class and it is throwing two exceptions, in class B which is child class of A must throw less number of exceptions compare to A and child class B must throw same type of exceptions as class A , if the child class throws other type of exceptions compare to super then the program will not compile successfully.
So d) is correct.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.