Inheritance:

Acquiring the properties from parent class to child class. The class from which you will be inheriting the properties is called base class/ parent class/ super class. Inheritance
Note: Base class will not get the properties from derived class.

Uses of Inheritance:

1. Code reusability. 2. We can reduce the debugging time because the person who wrote that base class has already debugged that code. Note: In java we inherit using "extends" keyword.
                 class Base extends Object
                 {
                    public void disp()
                    {
                     System.out.println("Base display");
                     }
                 }
                 class Der extends Base
                  {
                    public void test()
                    {
                      System.out.println("derived test");
                    }
                  }
If your class does not extent any class then automatically it extends object class.

Assignment:

Find out what is there in object class. What all we can inherit into child class: --> ?We can inherit all the variables from parent class if it is not "private" and "default". Note: Assuming that derived class is in different package.
                    public class Base
                      {
                        int i;
                        protected int j;
                        public void disp()
                        {
                           System.out.println("Base Display");
                        }
                      }
                     class Der extends Base
                     {
                         public void test()
                         {
                            System.out.println("derived test");
                          }
                     }
--> If the child class is in same package then we can access default variables also. --> You can inherit all the method from parent class if they are not private and default and if your child class is in different package. Note: -->If child class is in same package then you can inherit default methods also. -->You can inherit nested alas of present class into the derived class if it is not private. -->Constructors will not be inherited into the derived class but you can call super class constructor using "super()" keyword. We can do below things in the derived class: -->You can access directly all the classes of parent class if they are not private. -->You can create same variable name in the derived class as in the base class. Note: This is called as "Hiding"
 
                public class Base
                {
                   int i=10;
                   int j=200;
                   public void disp()
                   {
     
                   }
                }
               class Der extends Base
               {
                   int i=100;
                   public void test()
                   {
                       System.out.println(i);
                       System.out.println(j);
                    }
              }
. Note: This is not recommended. --> You can access all the functions of base class directly in the derived class if it is not private.
 
      public class Base
       {
          int i=10;
          int j=200;
          public void disp()
          {
            System.out.println(i);
          }
       }
      class Der extends Base
      {    
          int i=100;
          public void test()
          {
             disp();
          }
       }
--> We can create same function in the derived class with same signature as in base class. Note: If that function is instance function then this is called as "overriding".
 
                public class Base
                {
                     int i=10;
                     int j=200;
                     public void disp()
                     {
                      System.out.println(i);
                     }
                }
                class Der extends Base
                {
                     int i=100;
                     public void disp()
                     {
                       System.out.println("derived disp");
                     }
                 }
--> If you create some function in base class and derived class with same signature and if that function is static function then it is called as function hiding
      public class Base
      {
          int i=10;
          int j=200;
          public static void disp()
          {
             System.out.println("base static");
          }
          public static void test()
          {
             System.out.println("der static");
           }
      }
--> You can call base class constructors from derived class constructors. Note: 1. Constructors will not be inherited. 2. If constructors gets inherited then there is a chance of base class constructors which may lead to some dangerous side effects.
 
         class Base
           {
               private int i=10;
               int j=100;
               protected int k=30;
               public int l=40;
               public void disp()
               {
                 System.out.println("base disp");
               }
               public static void fun()
               { 
                 System.out.println("base static");
               }
        }
       class Der extends Base
       {
              int k = 300;
              public void test()
              {
               System.out.println(i);
               System.out.println(j);
               fun();
               }
               public void disp()
               {
                  System.out.println("der disp");
                }
          }