Polymorphism

In object-oriented programming, polymorphism is a concept where a function behaves differently, depending on the type of object that calls it. To understand the concept of polymorphism, we will continue with the Shape class example. Every shape has its own type and dimensions, but all shapes can be drawn on the screen. When the Circle class calls the draw function, it calculates the area and draws it. Similarly, if the Triangle class calls the draw function, it calculates the base and height and draws it. The same applies to the other classes. The idea behind polymorphism is that the draw function can display different shapes and the program can determine which shape of the function to call at the time of execution. There are different types of polymorphism used in Kotlin. In this section, we are discussing inheritance-based polymorphism. The idea behind this is that the base class can define a function and the derived class can override it by providing its own definition.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.175