ContactUs :

Please send your Questions & Answers or Feedback to "mohan@javabook.org"

How Polymorphism supported in Java ?

Java has excellent support of polymorphism in terms of Inheritance, method overloading and method overriding. Method overriding allows Java to invoke method based on a particular object at run-time instead of declared type while coding. To get hold of concept let's see an example of polymorphism in Java:

 

public class TradingSystem{

   public String getDescription(){

      return "electronic trading system";

   }

}

 

public class DirectMarketAccessSystem extends TradingSystem{

   public String getDescription(){

     return "direct market access system";

   }

}

 

public class CommodityTradingSystem extends TradingSystem{

   public String getDescription(){

     return "Futures trading system";

   }

}

 

Method overloading and method overriding uses concept of Polymorphism in Java where method name remains same in two classes but actual method called by JVM depends upon object at run time and done by dynamic binding in Java. Java supports both overloading and overriding of methods. In case of overloading method signature changes while in case of overriding method signature remains same and binding and invocation of method is decided on runtime based on actual object.

Related Posts Plugin for WordPress, Blogger...
Flag Counter