First about Constructors :
- When an object class is ever created, its constructor initialized and at that time immediately its constructor s uper-class is called before the class object ,
- In this process, all instance variables are declared and initialized.
- Consider this scenario.
The dog is a sub-class Canine , and Canine is a sub-class Animal
Now, when the Dog object is initialized before the object is actually formed, the object of the Canine class must be formed, and before the Canine object can form the object of the Animal class, it must be formed, and before this object of the Object class must be shaped
Thus, the sequence of the formed object:
Object ---> Animal ---> Canine ---> Dog
So, Constructor of the Super-Class is Called before the Sub-Class .
Now with Method :
The most specific version of the method that class is called.
For instance:
public class A{ public void go(){ } } class B extends A{ public static void main(String[] args){ new B().go();
source share