Menu

Post image 1
Post image 2
1 / 2
0

I Didn’t Understand Polymorphism Until This One Line of Code

DEV Community·Haruka·29 days ago
#ktiJJUbq
#why#java#fullscreen#ramen#enter#exit
Reading 0:00
15s threshold

When I saw this line in my paper-based quiz, I had no idea what it would do: Ramen r = new TonkotsuRamen (); System . out . println ( r ); Enter fullscreen mode Exit fullscreen mode I thought I understood polymorphism, but this simple line proved me wrong. The Example I Was Working With To better understand the concept, I recreated a simplified version of the problem: abstract class Ramen {     public abstract String getName ();       public String serve () {         return "Serving " + getName ();     } }   class TonkotsuRamen extends Ramen {     @Override     public String getName () {         return "Tonkotsu Ramen" ;     }       @Override     public String serve () {         return super .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More