This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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: 594
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: 7552
    
  18

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: 2840
    
  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: 594
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is readability the only advantage of polymorphism in java
 
Similar Threads
please help me out in casting of reference variable
generics doubt
instanceOf Confusion
class cating
polymorphism