class Animal {
protected Animal(){
System.out.println("ANIMAL CONSTRUCTOR");
}
public void move(){
System.out.println("ANIMAL Move");
}
}
class Dog extends Animal{
public Dog(){
System.out.println("Dog Constructor");
}
public void move(){
System.out.println("Dog move");
}
}
public class Test {
public static void main(String args[]){
Dog d = new Dog();
d.move();
}
}
The code above yields the result below:
ANIMAL CONSTRUCTOR
Dog Constructor
Dog move
It seems that when dog instance is created, it also calls Animal constructor by default (implicitly).
Which is strange because I was thinking explicitly calling super()
can do the same job.
Is there any way to break this constructor chain and let my dog instance only call Dog constructor?
if there is not, is there reason for it?