Order of Execution
- Parent Static Block
- Child Static Block
- Parent Normal Block
- Parent Constructor
- Child Normal Block
- Child Constructor
- 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