To quote this excellent Answer by cletus on a similar Question:
If the subclass constructor does not specify which superclass constructor to invoke then the compiler will automatically call the accessible no-args constructor in the superclass.
So let's try your scenario.
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Dog d = new Dog() ;
System.out.println( d ) ;
}
}
class Animal
{
Animal()
{
System.out.println( "Animal" ) ;
}
}
class Mammal extends Animal
{
Mammal()
{
System.out.println( "Mammal" ) ;
}
}
class Canine extends Mammal
{
Canine()
{
System.out.println( "Canine" ) ;
}
}
class Dog extends Canine
{
Dog()
{
System.out.println( "Dog" ) ;
}
}
See that code run live at IdeOne.com.
Animal
Mammal
Canine
Dog
Dog@452b3a41
Effectively, the compiler has added a call to the available no-arg constructor of each superclass, super()
. Like this:
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Dog d = new Dog() ;
System.out.println( d ) ;
}
}
class Animal
{
Animal()
{
super() ;
System.out.println( "Animal" ) ;
}
}
class Mammal extends Animal
{
Mammal()
{
super() ;
System.out.println( "Mammal" ) ;
}
}
class Canine extends Mammal
{
Canine()
{
super() ;
System.out.println( "Canine" ) ;
}
}
class Dog extends Canine
{
Dog()
{
super() ;
System.out.println( "Dog" ) ;
}
}
You can write that call explicitly in your code, if you like, to make clear to the reader that you want to rely on the superclass’ available no-arg constructor being called. You can see the explicit calls working in this code on IdeOne.com.