java2db

What is inheritance in java object oriented programming



Inheritance is nothing but reusability . It can be achieve by extending one class into one or more classes using  extends  keyword or implementing one or more interfaces  in a class using implements keyword.

 

inheritance in java extends

inheritance in java  Cannot extends an interface in a class.
inheritance in java  A class can extends another class.
inheritance in java  An interface can extends another interface.
inheritance in java  An interface cannot extends a class.

break continue and return implements
inheritance in java  Cannot implements an interface in another interface.
inheritance in java  A class can implements an interface.
inheritance in java  A class cannot implements another class.
inheritance in java  An interface cannot implements a class.

 

 inheritance in java Inheritance using extends keyword :

Execution Result:

inheritance in java circle is the base class having one variable (pi_value)  and one method  (circle_Area(float radius)) with public access specifier.
inheritance in java The class inheritanceDemo extends circle which is having the main method and  perimeter(float radius).
inheritance in java Now  inheritanceDemo  class is called derived class , it can be used the base class (circle) public variables and methods .
inheritance in java The method  perimeter(float radius) is calculating the perimeter using pi_value variable from the base class (circle).

 

It is not possible  to extend more than one class  at a time (multiple inheritance is not possible with extends ) .

In this case follow the example code below.

 

 break continue and return Inheritance using implements keyword :

Execution Result:

inheritance in java The circleInterface  having one final variable (pi_value) and one unimplemented  method called (circle_Area(float radius)).

inheritance in java Another interface shapeDemoInterface having circle_Area(float radius) and square_Area(float length).

inheritance in java Implemented the two interfaces (circleInterface  ,shapeDemoInterface ) unimplemented methods  in inheritanceDemo class .

inheritance in java Created two objects for inheritanceDemo with circleInterface  and shapeDemoInterface.

inheritance in java It is possible to implement more interfaces in a class, even though having same methods.

 




Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
How to Connect Liferay 7 to PostgreSQL ( Java Liferay portlet and PostgreSQL integration )
How to call C# .Net WCF web service in java SOAP client ( Visual Studio 2013 )
How to call PHP RESTful web service in java client
How to call java SOAP web service in php ( php web service client )
Solution to SSLHandshakeException (skip the certificate for Java and LDAP bind)
Java RESTful web service example in maven using JAX-RS
RESTful web service example in java using JAX-RS
   [will not be published]



^ <