QN038. Create a class foam class which is extending from Wood class and create Duster class which extend from wood class and implement.
1. Objective
To create a class foam class which is extending from wood class and create Duster class which extend from wood class.
2. Theory
When two or more classes inherits a single class, it is known as hierarchical Inheritance. In this program Foam and Duster class inherits Wood.
3. Source Code
      class Wood{ 
      void create(){
          System.out.println("Wood is created..");
        } 
      }
      
      class Foam extends Wood{
        void insert(){
          System.out.println("Foam inserted..");
        }
      }
      
      class Duster extends Wood{
        void apply(){
          System.out.println("Wood applied..");
        }
      }
      
      public class Qn038{
        public static void main(String[] args){
          Duster d = new Duster();
          d.create();
          d.apply();
          //d.insert();//compile time error
        }
      }
    
    4. Output
    Wood is created.. 
    Wood appled..
    
5. Conclusion
In this way, I would like to conclude that we can also inherits class in hierarchical way but we can not access methods from sub classes from object of subclass.