• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is readability the only advantage of polymorphism in java

 
Monica Shiralkar
Ranch Hand
Posts: 843
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10430
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greg Charles
Sheriff
Posts: 2987
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 843
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic