Forums Register Login

is readability the only advantage of polymorphism in java

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
thanks
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 896 times.
Similar Threads
polymorphism
please help me out in casting of reference variable
class cating
instanceOf Confusion
generics doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:19:01.