Ads Sponsored By Google :)

Sunday 13 January 2013

Definition of multiple inheritance using interface in java with example


multiple inheritance using interface in java multiple inheritance using interface in java with example example for multiple inheritance using interface in java definition of multiple inheritance

Multiple Inheritance: 

        Multiple inheritance is one in which their exists multiple base classes and single derived classes.  Multiple inheritance using classes is not possible, but by using interfaces multiple    inheritance can be achieved.

Multiple Inheritance is one of the Factor that makes Java is not 100%  pure object oriented programming language. 

Achieving the multiple inheritance in java by using Inheritance, makes java is not pure object oriented programming language. Because we cannot instantiate the object for the interface directly.

Click Here For Important Reasons Why Java is not 100% pure Object Programing Language ?
 


The following example illustrate the concept of Multiple inheritance by using interfaces

       interface car
      {
        int  speed=90;
        public void distance();
      }
      interface bus
     {
       int distance=100;
       public void speed();
     }
      class vehicle  implements car,bus
    {
      public void distance()
     {
      int  distance=speed*100; 
      System.out.println(“distance travelled is”+distance);
     }
       public void speed()
     {
       int speed=distance/100;
     }
    }
       class maindemo
     {
        public static void main(String args[])
      {
        System.out.println(“w.r.t  Vehicle”);
       Vechicle v1=new Vehicle();
       v1.distance();
       v1.speed();
      }
      }

No comments:

Post a Comment

LinkWithin