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

Home > Java Programming > Exceptions > Questions and Answers

Q: What is the output for the below code ?

public class SuperClass {
public int doIt(String str, Integer... data)throws ArrayIndexOutOfBoundsException{
String signature = "(String, Integer[])";
System.out.println(str + " " + signature);
return 1;
}
}

public class SubClass extends SuperClass{
public int doIt(String str, Integer... data) throws Exception{
String signature = "(String, Integer[])";
System.out.println("Overridden: " + str + " " + signature);
return 0;
}

public static void main(String... args){
SuperClass sb = new SubClass();
try{
sb.doIt("hello", 3);
}catch(Exception e){

}
}
}
A. Overridden: hello (String, Integer[]) B. hello (String, Integer[])
C. This code throws an Exception at Runtime D. Compile with error

Answer and Explanation

Answer:Compile with error

Explanation:
Exception is not compatible with throws clause in SuperClass.doIt(String, Integer[]).
The same exception or subclass of that exception is allowed.


Comment on this Question

Name:

Loading...




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