This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It gives compile time error.
It seems to me that compiler insert no-arg default constructor for class Cert. and don't find no-arg constructor in Marmaduke.
when a object is instantiated for subclass , then instantiation of its super class must be done first. i.e you have to complete the UP hierarchy
my doubt is :
i am creating instance of Marmaduke class . So i must ensure the instantiation of Marmaduke and Object class which is UP hierarchy.which is fine since compiler will place super() in Marmaduke fo Object class.
but why do i have to worry about the Cert i.e. DOWN hierarchy ??
Extending class has to define constructor, which can call constructor of extended class with corresponding argument list. Compiler puts call to super(...) constructor in every first line of your extending class constructors.
You don't define any constructor in extending class, so compiler puts default no-arg, but it cannot insert call to super() with no args, so refuses to compile such a code.
It doesn't matter you don't instantiate extended class in your code.
it means compiler will check constructor for every class in parent and child class relationship , irrespective of class you are instantiating.
it starts constructor chaining right form child class to Object class. Is that it ?
Yes, exatcly. Please notice, that you can instatiate object without using new operator - ie. you can do this dynamically with reflection API - how compiler would determine if you would or would not do this?