Problem statement: what will be the output of the below code?
class A {
public void run() throws ArithmeticException {
System.out.println("A");
}
}
class B extends A {
public void run() throws Exception {
System.out.println("B");
}
}
public class ExceptionClass {
public static void main(String args[]) {
A a = new B();
a.run();
}
}
Output:
compilation error
run() method in A class clashes with run() method in B class.
Overriden method does not have subclass of ArithmaticException class.
so there is no visibility of Exception class from the parent class.
class A {
public void run() throws ArithmeticException {
System.out.println("A");
}
}
class B extends A {
public void run() throws Exception {
System.out.println("B");
}
}
public class ExceptionClass {
public static void main(String args[]) {
A a = new B();
a.run();
}
}
Output:
compilation error
run() method in A class clashes with run() method in B class.
Overriden method does not have subclass of ArithmaticException class.
so there is no visibility of Exception class from the parent class.
No comments:
Post a Comment