Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Implementing Polymorphism Using Inheritance

Sumit Rawal answered on May 17, 2023 Popularity 9/10 Helpfulness 1/10

Contents


More Related Answers

  • is overriding and overloading polymorphism
  • what is polymorphism
  • Java Polymorphism
  • what is polymorphism
  • inheritance vs polymorphism in java
  • demonstrating polymorphism in python class
  • Polymorphism
  • C++ polymorphism
  • c++ polymorphism
  • What is Polymorphism?
  • polymorphism
  • C++ Polymorphism
  • can we say Polymorphism is a concept in OOP that allows data to be in multiple forms?
  • polymorphism in c++
  • polymorphism java
  • Dynamic polymorphism example#
  • Runtime polymorphism in java
  • polymorphism javascript
  • What is Polymorphism
  • What do you mean by Polymorphism ? Explain it with an example ?
  • polymorphism vs overriding in java
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • does polymorphism allow reuse of code?
  • where do you use polymorphism in framework
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • Javascript Encapsulation Inheritance Polymorphism Composition
  • Javascript Encapsulation Inheritance Polymorphism Composition

  • Implementing Polymorphism Using Inheritance

    0

    We can add new data and methods to a class through inheritance. But what if we want our derived class to inherit a method from the base class and have a different implementation for it? That is when polymorphism, a fundamental concept in the OOP paradigm, comes into play.

    Example

    Consider the example of a Shape class, which is the base class while many shapes like Rectangle and Circle extending from the base class are derived classes. These derived classes inherit the getArea() method and provide a shape-specific implementation, which calculates its area.

    Rectangle and circle inherit from shape

    Implementation

    We will be implementing the parent class first, and then the child classes.

    Shape class

    The Shape class has only one public method called getArea().

    Let’s look at the implementation of the Shape class: 

    Popularity 9/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.