Inheritance and Constructors:

       class Base 
       {
         public Base()
         {
           System.out.println("base constructors");
         }
       }
      class Der extends Base     
      {
          public Der()
          { 
           System.out.println("Der constructor");
          }
        }
        public class MainClass
        {
          public static void main(String[] args)
          {
            Base b=new Base();
            Der d=new Der();
          }
      }
Note: When you are creating object for derived class first it calls base class constructors and then it calls derived class constructor. --> Before calling derived class constructor you have to initialize base class variables because may be in the derived class constructors we are using some of the base class variables. Note: --> In every constructor java compiler will add "super()" call as the first line. --> It will not add super call if the constructor is already having "this"/"super" keywords in the first line.

Cycle of the constructor execution:

       class Base extends Object
       {
          public Base()
          {
            System.out.println("base constructor");
          }
       }
       class Der extends Base
       {
          public Der()
           {
             super();
             nSystem.out.println("Der Constructor");
            }
        }
        public class MainClass
         {
              public static void main(String[ ]  args)
              {
                 Base b=new Base();
                 Der d = new Der();
              }
        }
Example: Cycle of constructor
           class Object
           {
              public Object()
           {
	 
           }
         }
            class Rect extends Object
            {
              int len,bred;
              public Rect(int l, int b)
              {
                 super();
                 len =l;
                 bred=b;
               }
               public Rect(int side)
               {
                  len=side;
                  bred=side;
                }
            public void findArea()
            {
                System.out.println(len*bred);
             }
          }
--> Derive one class without construction and base class with one constructor without parameter.
 
                class Object
                {
	
                }
                class Base
                {
                    public Base()
                    {
                       super();
                       System.out.println("Base Constructor");
                     }
                 }
                class Der extends Base
                {
                   public Der()   
                   {
                    super();
                   }
                   public void fun()
                  {
                    System.out.println("der function");
	          }
	         }
	         public class MainClass
	          {
	           public static void main(String[ ] args)
	            {
   	            Der d= new Der();
 	            }
	        }

Default Constructor:

If your class is not having any constructor then compiler will automatically add a default constructor.

Properties of default constructor:

--> It will be public and have no parameters. --> It will have only one line. i.e., ".super call". Derived class with no constructor and base class with one parameterized constructor.
    class Object
    {
     ...
    }
   class Base
   {
     int i;
     public Base(int z)
     {
        super();
        i=z;
        System.out.println("base const");
      }
    }
   class Der extends Base
   {
     public Der()
     {
       super(10);
      }
    public void fun()
    {
       System.out.println("der function");
     }
   }
   public class MainClass
   {
      public static void main(String[ ] args)
      {
        Der d=new Der();
      }
   }
Derive class with parameterized constructor and base class with parameter less constructor.
    class Object
    {
       ...
    }
    class Base
    { 
     public Base()
     {
       super();
       System.out.println("base constructor");
     }
   }
   class Der extends Base
   {
     int i;
     public Der(int z);
     { 
        super();
        i=z;
     }
     public void fun()
     {
        System.out.println("der function");
     }
   }

   public class MainClass
   { 
     public static void main(String[] args)
     {
       Der d=new Der(10);
      }
    }

Assignment:

Default constructor
	class Emp
	{
 	     private int eno;
  	     private String ename;
   	     private int esal;
   	     public Emp(int no,String name,int sal)
	     {
	         eno=no;
  	         ename=name;
  	         esal=sal;
	     }
	     public void dispEmp()
	     {
	         System.out.println(eno);
  	         System.out.println(ename);
  	         System.out.println(esal);
	     }
        }
	  class Trainer extends Emp
	   {
	         private String tsub;
	         private int  tincentives;
	         public Trainer(int no,String name,int sal,String sub)
	         {
	             super(no,name,sal);
	             tsub=sub;
	             tincentives=(sal*30)/100;
	          }
 	         public void dispTrainer()
	         {
  	             dispEmp();
  	             System.out.println(tsub);
   	             System.out.println(tincentives);
	          }
	   }
	   public class TrainerDemo
	   {
	         public static void main(String[] args)
	        {
  	           Trainer t= new Trainer(1,"andy",1000,"android");
   	           t.dispTrainer();
	         }
	   }