This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes is readability the only advantage of polymorphism in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "is readability the only advantage of polymorphism in java" Watch "is readability the only advantage of polymorphism in java" New topic
Author

is readability the only advantage of polymorphism in java

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
In java we can have polymorphism. Super type can be made to refer to sub type. E.g Animal referring to Dog. But whether Animal refers to Dog or Dog refers to Dog ,at runtime the method called will be of Dog type only.So the what was the benfit which we got here because of Polymorphism. One advantage is readibility.Is it the only advantage or there is some other advantage too.

thanks.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  20

Monica. Shiralkar wrote:One advantage is readibility.Is it the only advantage or there is some other advantage too.

There are lots of advantages, the main of which is to be able to deal with multiple similar types automatically, without the need for "dispatch logic" - ie:Indeed, if you see a Java program with lots of code like that, it often means that the designer didn't use polymorphism when they probably should have.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

There are lots of advantages, as Winston points out, but if you want to get really technical, they all boil down to easier for programers to write and easier for programers to read. In fact, all computer languages, from assembly on up, are exclusively meant to simplify the interface of binary computers to human programers. The computer would be just as happy if we wrote everything in machine language, but we wouldn't be.
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is readability the only advantage of polymorphism in java