Posts

Showing posts from January, 2017

Types of Inheritance in Java

There are five types of inheritance . Types are 1)Single 2) Multilevel 3) Multiple 4) Hybrid 5) Hierarchical . But Java supports four types of inheritance . Java does not support " Multiple Inheritance ". 1) Single :                 public class A{              ................           }          public class B extends A{                        .................          }          Supports     2) Multilevel :         public class A{              ................           }          public class B extends A{                        .................          }               public class C extends B{                        .................          }      Supports   3) Multiple :        public class A{              ................           }        public class B{              ................           }        public class C extends A,B{              ................           }       It's generate a compile time

Inheritance in Java

Inheritance   is one of the feature of Object-Oriented Programming . Inheritance allows a class to use the properties and methods of another class. When a class "ABC" can access  the properties and method of a class "XYZ" then the "XYZ" class is called " Parent/Super " class and the "ABC" class is called " Sub/Derived " class . Syntax is     class XYZ{       //  write your logic here    }  class ABC extends XYZ{     // write  your logic here } Example : class A  {     int x;      public void display()      {           System.out.println("Value of X is :"+x);      } } public class B extends A{     public static void main(String []args)   {      A obj=new A();      obj.x=10;      obj.display();   } } Output :                Value of X is : 10            Find us :         Facebook : @apnaandroid         Google+   : Apna Java         Youtube : Android & Java Tutorial