Friday, 23 November 2018

Inheritance and Conditions


  1. When Parent throws Generic Exception and Child throws specific exception
    1. Compiles and run successfully
    2. 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 .....
  2. When Parent throws specific exception and child throws generic exception
    1. Compile time error
  3. When Parent modifier is protected and child modifier is public
    1. Compiles and run successfully
  4. When Parent modifier is private and child modifier is public
    1. Compile time error
  5. When Parent modifier is public and child modifier is private
    1. Compile time error

No comments:

Post a Comment

Search This Blog

Contact us

Name

Email *

Message *