Friday, 15 September 2017

Order of Execution in java Inheritance


Order of Execution
  1. Parent Static Block 
  2. Child Static Block 
  3. Parent Normal Block 
  4. Parent Constructor 
  5. Child Normal Block 
  6. Child Constructor
  7. Child method invoked

Animal.java 
public class Animal { static { System.out.println("Animal Static Block "); } public Animal() { System.out.println("Animal Consuctor"); } { System.out.println("Animal Normal Block"); } public void aboutMe() { System.out.println("I am a Animal"); } }
Cow.java
public class Cow extends Animal { static { System.out.println("Cow Static Block "); } public Cow() { System.out.println("Cow Consuctor"); } { System.out.println("Cow Normal Block"); } public void aboutMe() { System.out.println("I am a Cow"); } }
App.java
public class App { public static void main(String[] args) { Cow cow = new Cow(); cow.aboutMe(); } }

No comments:

Post a Comment

Search This Blog

Contact us

Name

Email *

Message *