- When Parent throws Generic Exception and Child throws specific exception
- Compiles and run successfully
public class Animal { public void eat() throws Exception { System.out.println("Animal Eating..."); } } public class Cat extends Animal { @Override public void eat() throws FileNotFoundException { System.out.println("Cat Eating ....."); } } public class App { public static void main(String[] args) throws Exception { Animal cat = new Cat(); cat.eat(); } } ######### RESULT ########## Cat Eating .....
- When Parent throws specific exception and child throws generic exception
- Compile time error
- When Parent modifier is protected and child modifier is public
- Compiles and run successfully
- When Parent modifier is private and child modifier is public
- Compile time error
- When Parent modifier is public and child modifier is private
- Compile time error
Friday, 23 November 2018
Inheritance and Conditions
About Unknown
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment