Inheritance Task

Create program to find area of Triangle using inheritance.

Solution:

<?php  
    class getdata  
    {  
        public $h;  
        public $b;  
        public function method1()  
        {  
            $this->h= $_REQUEST['height'];  
            $this->b= $_REQUEST['base'];  
        }  
  
    }  
    classfindarea extends getdata  
    {  
        public $area;  
        public function method2()  
        {  
            $this->area= ($this->h* $this->b)/2;  
            echo "Area of Triangle is : ".$this->area;  
        }  
    }  
    if(isset($_REQUEST['submit']))  
    {  
        $obj = new findarea();  
        $obj->method1();  
        $obj->method2();  
    }  
  
      
?>  
<html>  
<head>  
</head>  
<body>  
    <form method= "post">  
        <table align ="left" border="1">  
        <tr>  
            <td> Enter Height </td>  
            <td><input type = "text" name="height"/></td>  
        </tr>  
        <tr>  
            <td> Enter Base </td>  
            <td><input type = "text" name="base"/></td>  
        </tr>  
        <tr>  
            <td align ="center" colspan="2">  
            <input type= "submit"name="submit"value="click"/>  
        </td>  
        </tr>  
        </table>  
        </form>  
</body>  
</html>  

Output:

Inheritance Task
Inheritance Task
Inheritance Task

Interface

  • An interface is similar to a class except that it cannot contain code.
  • An interface can define method names and arguments, but not the contents of the methods.
  • Any classes implementing an interface must implement all methods defined by the interface.
  • A class can implement multiple interfaces.
  • An interface is declared using the “interface” keyword.
  • Interfaces can’t maintain Non-abstract methods.

Example 1

<?php  
    interface a  
    {  
        public function dis1();  
    }  
    interface b  
    {  
        public function dis2();  
    }  
  
class demo implements a,b  
{  
    public function dis1()  
    {  
        echo "method 1...";  
    }  
    public function dis2()  
    {  
        echo "method2...";  
    }  
}  
$obj= new demo();  
$obj->dis1();  
$obj->dis2();  
  
?>  

Output:

method 1…method 2…

Example 2

  

<?php  
    interface i1  
    {  
        public function fun1();  
    }  
    interface i2  
    {  
        public function fun2();  
    }  
class cls1 implements i1,i2  
{  
    function fun1()  
    {  
        echo "protutorials";  
    }  
    function fun2()  
    {  
        echo "tech";  
    }  
}  
$obj= new cls1();  
$obj->fun1();  
$obj->fun2();  
  
?>

Output:

protutorialstech

Inheritance

It is a concept of accessing the features of one class from another class. If we inherit the class features into another class, we can access both class properties. We can extends the features of a class by using ‘extends’ keyword.

  • It supports the concept of hierarchical classification.
  • Inheritance has three types, single, multiple and multilevel Inheritance.
  • PHP supports only single inheritance, where only one class can be derived from single parent class.
  • We can simulate multiple inheritance by using interfaces.

Example 1

<?php  
class a  
    {  
        function fun1()  
        {  
            echo "protutorials";  
        }  
    }  
    class b extends a  
    {  
        function fun2()  
        {  
            echo "SSSIT";  
        }  
    }  
    $obj= new b();  
    $obj->fun1();  
?>  

Output:

protutorials

Example 2

<?php  
    class demo  
    {  
        public function display()  
        {  
            echo "example of inheritance  ";  
        }     
    }  
    class demo1 extends demo  
    {  
        public function view()  
        {  
            echo "in php";  
        }     
    }  
    $obj= new demo1();  
    $obj->display();  
    $obj->view();  
?>

Output:

example of inheritance in php

Kotlin inheritance

Inheritance is one of the key features of object-oriented programming. It allows user to create a new class (derived class) from an existing class (base class).

The derived class inherits all the features from the base class and can have additional features of its own.

Before going into details about Kotlin inheritance, we recommend you to check these two articles:

  • Kotlin Class and Objects
  • Kotlin Primary Constructor

Why inheritance?

Suppose, in your application, you want three characters – a math teacher, a footballer and a businessman.

Since, all of the characters are persons, they can walk and talk. However, they also have some special skills. A math teacher can teach math, a footballer can play football and a businessman can run a business.

You can individually create three classes who can walk, talk and perform their special skill.

Example of classes sharing same features without the use of inheritance.

In each of the classes, you would be copying the same code for walk and talk for each character.

If you want to add a new feature – eat, you need to implement the same code for each character. This can easily become error prone (when copying) and duplicate codes.

It would be a lot easier if we had a Person class with basic features like talk, walk, eat, sleep, and add special skills to those features as per our characters. This is done using inheritance.

Example of inheritance in OOP

Using inheritance, now you don’t implement the same code for walk()talk() and eat() for each class. You just need to inherit them.

So, for MathTeacher (derived class), you inherit all features of a Person (base class) and add a new feature teachMath(). Likewise, for the Footballer class, you inherit all the features of the Person class and add a new feature playFootball() and so on.

This makes your code cleaner, understandable and extendable.

It is important to remember: When working with inheritance, each derived class should satisfy the condition whether it “is a” base class or not. In the example above, MathTeacher is a PersonFootballer is a Person. You cannot have something like, Businessman is a Business.


Kotlin inheritance

Let’s try to implement the above discussion in code:

open class Person(age: Int) {
    // code for eating, talking, walking
}

class MathTeacher(age: Int): Person(age) {
    // other features of math teacher
}

class Footballer(age: Int): Person(age) {
    // other features of footballer
}

class Businessman(age: Int): Person(age) {
    // other features of businessman
}

Here, Person is a base class, and classes MathTeacherFootballer, and Businessman are derived from the Person class.

Notice, the keyword open before the base class, Person. It’s important.

By default, classes in Kotlin are final. If you are familiar with Java, you know that a final class cannot be subclassed. By using the open annotation on a class, compiler allows you to derive new classes from it.


Example: Kotlin Inheritance

open class Person(age: Int, name: String) {
    init {
        println("My name is $name.")
        println("My age is $age")
    }
}

class MathTeacher(age: Int, name: String): Person(age, name) {

    fun teachMaths() {
        println("I teach in primary school.")
    }
}

class Footballer(age: Int, name: String): Person(age, name) {
    fun playFootball() {
        println("I play for LA Galaxy.")
    }
}

fun main(args: Array<String>) {
    val t1 = MathTeacher(25, "Jack")
    t1.teachMaths()

    println()

    val f1 = Footballer(29, "Christiano")
    f1.playFootball()
}

When you run the program, the output will be:

My name is Jack.
My age is 25
I teach in primary school.

My name is Cristiano.
My age is 29
I play for LA Galaxy.

Here, two classes MathTeacher and Footballer are derived from the Person class.

The primary constructor of the Person class declared two properties: age and name, and it has an initializer block. The initilizer block (and member functions) of the base class Person can be accessed by the objects of derived classes (MathTeacher and Footballer).

Derived classes MathTeacher and Footballer have their own member functions teachMaths() and playFootball() respectively. These functions are accessible only from the objects of their respective class.


When the object t1 of MathTeacher class is created,

val t1 = MathTeacher(25, "Jack")

The parameters are passed to the primary constructor. In Kotlin, init block is called when the object is created. Since, MathTeacher is derived from Person class, it looks for initializer block in the base class (Person) and executes it. If the MathTeacher had init block, the compiler would have also executed the init block of the derived class.

Next, the teachMaths() function for object t1 is called using t1.teachMaths() statement.

The program works similarly when object f1 of Footballer class is created. It executes the init block of the base class. Then, the playFootball() method of Footballer class is called using statement f1.playFootball().


Important Notes: Kotlin Inheritance

  • If the class has a primary constructor, the base must be initialized using the parameters of the primary constructor. In the above program, both derived classes have two parameters age and name, and both these parameters are initialized in primary constructor in the base class.

    Here’s another example:open class Person(age: Int, name: String) { // some code } class Footballer(age: Int, name: String, club: String): Person(age, name) { init { println("Football player $name of age $age and plays for $club.") } fun playFootball() { println("I am playing football.") } } fun main(args: Array<String>) { val f1 = Footballer(29, "Cristiano", "LA Galaxy") } Here the primary constructor of the derived class has 3 parameters, and the base class has 2 parameters. Note that, both parameters of the base class are initialized.
     
  • In case of no primary constructor, each base class has to initialize the base (using super keyword), or delegate to another constructor which does that. For example,fun main(args: Array<String>) { val p1 = AuthLog("Bad Password") } open class Log { var data: String = "" var numberOfData = 0 constructor(_data: String) { } constructor(_data: String, _numberOfData: Int) { data = _data numberOfData = _numberOfData println("$data: $numberOfData times") } } class AuthLog: Log { constructor(_data: String): this("From AuthLog -> + $_data", 10) { } constructor(_data: String, _numberOfData: Int): super(_data, _numberOfData) { } }To learn more on how this program works, visit Kotlin Secondary Constructor.

Overriding Member Functions and Properties

If the base class and the derived class contains a member function (or property) with the same name, you can need to override the member function of the derived class using override keyword, and use open keyword for the member function of the base class.


Example: Overriding Member Function

// Empty primary constructor
open class Person() {
    open fun displayAge(age: Int) {
        println("My age is $age.")
    }
}

class Girl: Person() {

    override fun displayAge(age: Int) {
        println("My fake age is ${age - 5}.")
    }
}

fun main(args: Array<String>) {
    val girl = Girl()
    girl.displayAge(31)
}

When you run the program, the output will be:

My fake age is 26.

Here, girl.displayAge(31) calls the displayAge() method of the derived class Girl.


You can override property of the base class in similar way.

Visit how Kotlin getters and setters work in Kotlin before you check the example below.

// Empty primary constructor
open class Person() {
    open var age: Int = 0
        get() = field

        set(value) {
            field = value
        }
}

class Girl: Person() {

    override var age: Int = 0
        get() = field

        set(value) {
            field = value - 5
        }
}

fun main(args: Array<String>) {

    val girl = Girl()
    girl.age = 31
    println("My fake age is ${girl.age}.")
}

When you run the program, the output will be:

My fake age is 26.

As you can see, we have used override and open keywords for age property in derived class and base class respectively.


Calling Members of Base Class from Derived Class

You can call functions (and access properties) of the base class from a derived class using super keyword. Here’s how:

open class Person() {
    open fun displayAge(age: Int) {
        println("My actual age is $age.")
    }
}

class Girl: Person() {

    override fun displayAge(age: Int) {

        // calling function of base class
        super.displayAge(age)
        
        println("My fake age is ${age - 5}.")
    }
}

fun main(args: Array<String>) {
    val girl = Girl()
    girl.displayAge(31)
}

When you run the program, the output will be:

My age is 31.
My fake age is 26.

Python Inheritance

Inheritance enables us to define a class that takes all the functionality from a parent class and allows us to add more. In this tutorial, you will learn to use inheritance in Python.

Inheritance in Python

Inheritance is a powerful feature in object oriented programming.

It refers to defining a new class with little or no modification to an existing class. The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class.


Python Inheritance Syntax

class BaseClass:
  Body of base class
class DerivedClass(BaseClass):
  Body of derived class

Derived class inherits features from the base class where new features can be added to it. This results in re-usability of code.


Example of Inheritance in Python

To demonstrate the use of inheritance, let us take an example.

A polygon is a closed figure with 3 or more sides. Say, we have a class called Polygon defined as follows.

class Polygon:
    def __init__(self, no_of_sides):
        self.n = no_of_sides
        self.sides = [0 for i in range(no_of_sides)]

    def inputSides(self):
        self.sides = [float(input("Enter side "+str(i+1)+" : ")) for i in range(self.n)]

    def dispSides(self):
        for i in range(self.n):
            print("Side",i+1,"is",self.sides[i])

This class has data attributes to store the number of sides n and magnitude of each side as a list called sides.

The inputSides() method takes in the magnitude of each side and dispSides() displays these side lengths.

A triangle is a polygon with 3 sides. So, we can create a class called Triangle which inherits from Polygon. This makes all the attributes of Polygon class available to the Triangle class.

We don’t need to define them again (code reusability). Triangle can be defined as follows.

class Triangle(Polygon):
    def __init__(self):
        Polygon.__init__(self,3)

    def findArea(self):
        a, b, c = self.sides
        # calculate the semi-perimeter
        s = (a + b + c) / 2
        area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
        print('The area of the triangle is %0.2f' %area)

However, class Triangle has a new method findArea() to find and print the area of the triangle. Here is a sample run.

>>> t = Triangle()

>>> t.inputSides()
Enter side 1 : 3
Enter side 2 : 5
Enter side 3 : 4

>>> t.dispSides()
Side 1 is 3.0
Side 2 is 5.0
Side 3 is 4.0

>>> t.findArea()
The area of the triangle is 6.00

We can see that even though we did not define methods like inputSides() or dispSides() for class Triangle separately, we were able to use them.

If an attribute is not found in the class itself, the search continues to the base class. This repeats recursively, if the base class is itself derived from other classes.


Method Overriding in Python

In the above example, notice that __init__() method was defined in both classes, Triangle as well Polygon. When this happens, the method in the derived class overrides that in the base class. This is to say, __init__() in Triangle gets preference over the __init__ in Polygon.

Generally when overriding a base method, we tend to extend the definition rather than simply replace it. The same is being done by calling the method in base class from the one in derived class (calling Polygon.__init__() from __init__() in Triangle).

A better option would be to use the built-in function super(). So, super().__init__(3) is equivalent to Polygon.__init__(self,3) and is preferred. To learn more about the super() function in Python, visit Python super() function.

Two built-in functions isinstance() and issubclass() are used to check inheritances.

The function isinstance() returns True if the object is an instance of the class or other classes derived from it. Each and every class in Python inherits from the base class object.

>>> isinstance(t,Triangle)
True

>>> isinstance(t,Polygon)
True

>>> isinstance(t,int)
False

>>> isinstance(t,object)
True

Similarly, issubclass() is used to check for class inheritance.

>>> issubclass(Polygon,Triangle)
False

>>> issubclass(Triangle,Polygon)
True

>>> issubclass(bool,int)
True

Python Object Oriented Programming

In this tutorial, you’ll learn about Object-Oriented Programming (OOP) in Python and its fundamental concept with the help of examples.

Object Oriented Programming

Python is a multi-paradigm programming language. It supports different programming approaches.

One of the popular approaches to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).

An object has two characteristics:

  • attributes
  • behavior

Let’s take an example:

A parrot is can be an object,as it has the following properties:

  • name, age, color as attributes
  • singing, dancing as behavior

The concept of OOP in Python focuses on creating reusable code. This concept is also known as DRY (Don’t Repeat Yourself).

In Python, the concept of OOP follows some basic principles:


Class

A class is a blueprint for the object.

We can think of class as a sketch of a parrot with labels. It contains all the details about the name, colors, size etc. Based on these descriptions, we can study about the parrot. Here, a parrot is an object.

The example for class of parrot can be :

class Parrot:
    pass

Here, we use the class keyword to define an empty class Parrot. From class, we construct instances. An instance is a specific object created from a particular class.


Object

An object (instance) is an instantiation of a class. When class is defined, only the description for the object is defined. Therefore, no memory or storage is allocated.

The example for object of parrot class can be:

obj = Parrot()

Here, obj is an object of class Parrot.

Suppose we have details of parrots. Now, we are going to show how to build the class and objects of parrots.

Example 1: Creating Class and Object in Python

class Parrot:

    # class attribute
    species = "bird"

    # instance attribute
    def __init__(self, name, age):
        self.name = name
        self.age = age

# instantiate the Parrot class
blu = Parrot("Blu", 10)
woo = Parrot("Woo", 15)

# access the class attributes
print("Blu is a {}".format(blu.__class__.species))
print("Woo is also a {}".format(woo.__class__.species))

# access the instance attributes
print("{} is {} years old".format( blu.name, blu.age))
print("{} is {} years old".format( woo.name, woo.age))

Output

Blu is a bird
Woo is also a bird
Blu is 10 years old
Woo is 15 years old

In the above program, we created a class with the name Parrot. Then, we define attributes. The attributes are a characteristic of an object.

These attributes are defined inside the __init__ method of the class. It is the initializer method that is first run as soon as the object is created.

Then, we create instances of the Parrot class. Here, blu and woo are references (value) to our new objects.

We can access the class attribute using __class__.species. Class attributes are the same for all instances of a class. Similarly, we access the instance attributes using blu.name and blu.age. However, instance attributes are different for every instance of a class.


Methods

Methods are functions defined inside the body of a class. They are used to define the behaviors of an object.

Example 2 : Creating Methods in Python

class Parrot:
    
    # instance attributes
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    # instance method
    def sing(self, song):
        return "{} sings {}".format(self.name, song)

    def dance(self):
        return "{} is now dancing".format(self.name)

# instantiate the object
blu = Parrot("Blu", 10)

# call our instance methods
print(blu.sing("'Happy'"))
print(blu.dance())

Output

Blu sings 'Happy'
Blu is now dancing

In the above program, we define two methods i.e sing() and dance(). These are called instance methods because they are called on an instance object i.e blu.


Inheritance

Inheritance is a way of creating a new class for using details of an existing class without modifying it. The newly formed class is a derived class (or child class). Similarly, the existing class is a base class (or parent class).

Example 3: Use of Inheritance in Python

# parent class
class Bird:
    
    def __init__(self):
        print("Bird is ready")

    def whoisThis(self):
        print("Bird")

    def swim(self):
        print("Swim faster")

# child class
class Penguin(Bird):

    def __init__(self):
        # call super() function
        super().__init__()
        print("Penguin is ready")

    def whoisThis(self):
        print("Penguin")

    def run(self):
        print("Run faster")

peggy = Penguin()
peggy.whoisThis()
peggy.swim()
peggy.run()

Output

Bird is ready
Penguin is ready
Penguin
Swim faster
Run faster

In the above program, we created two classes i.e. Bird (parent class) and Penguin (child class). The child class inherits the functions of parent class. We can see this from the swim() method.

Again, the child class modified the behavior of the parent class. We can see this from the whoisThis() method. Furthermore, we extend the functions of the parent class, by creating a new run() method.

Additionally, we use the super() function inside the __init__() method. This allows us to run the __init__() method of the parent class inside the child class.


Encapsulation

Using OOP in Python, we can restrict access to methods and variables. This prevents data from direct modification which is called encapsulation. In Python, we denote private attributes using underscore as the prefix i.e single _ or double __.

Example 4: Data Encapsulation in Python

class Computer:

    def __init__(self):
        self.__maxprice = 900

    def sell(self):
        print("Selling Price: {}".format(self.__maxprice))

    def setMaxPrice(self, price):
        self.__maxprice = price

c = Computer()
c.sell()

# change the price
c.__maxprice = 1000
c.sell()

# using setter function
c.setMaxPrice(1000)
c.sell()

Output

Selling Price: 900
Selling Price: 900
Selling Price: 1000

In the above program, we defined a Computer class.

We used __init__() method to store the maximum selling price of Computer. We tried to modify the price. However, we can’t change it because Python treats the __maxprice as private attributes.

As shown, to change the value, we have to use a setter function i.e setMaxPrice() which takes price as a parameter.


Polymorphism

Polymorphism is an ability (in OOP) to use a common interface for multiple forms (data types).

Suppose, we need to color a shape, there are multiple shape options (rectangle, square, circle). However we could use the same method to color any shape. This concept is called Polymorphism.

Example 5: Using Polymorphism in Python

class Parrot:

    def fly(self):
        print("Parrot can fly")
    
    def swim(self):
        print("Parrot can't swim")

class Penguin:

    def fly(self):
        print("Penguin can't fly")
    
    def swim(self):
        print("Penguin can swim")

# common interface
def flying_test(bird):
    bird.fly()

#instantiate objects
blu = Parrot()
peggy = Penguin()

# passing the object
flying_test(blu)
flying_test(peggy)

Output

Parrot can fly
Penguin can't fly

In the above program, we defined two classes Parrot and Penguin. Each of them have a common fly() method. However, their functions are different.

To use polymorphism, we created a common interface i.e flying_test() function that takes any object and calls the object’s fly() method. Thus, when we passed the blu and peggy objects in the flying_test() function, it ran effectively.


C++ Inheritance

In this article, you’ll learn everything about inheritance in C++. More specifically, what is inheritance and different ways to implement it with examples.

Inheritance is one of the key features of Object-oriented programming in C++. It allows user to create a new class (derived class) from an existing class(base class).

The derived class inherits all the features from the base class and can have additional features of its own.


Why inheritance should be used?

Suppose, in your game, you want three characters – a maths teacher, a footballer and a businessman.

Since, all of the characters are persons, they can walk and talk. However, they also have some special skills. A maths teacher can teach maths, a footballer can play football and a businessman can run a business.

You can individually create three classes who can walk, talk and perform their special skill as shown in the figure below.

Solving a problem without inheritance in C++

In each of the classes, you would be copying the same code for walk and talk for each character.

If you want to add a new feature – eat, you need to implement the same code for each character. This can easily become error prone (when copying) and duplicate codes.

It’d be a lot easier if we had a Person class with basic features like talk, walk, eat, sleep, and add special skills to those features as per our characters. This is done using inheritance.

Solving a problem with inheritance in C++

Using inheritance, now you don’t implement the same code for walk and talk for each class. You just need to inherit them.

So, for Maths teacher (derived class), you inherit all features of a Person (base class) and add a new feature TeachMaths. Likewise, for a footballer, you inherit all the features of a Person and add a new feature PlayFootball and so on.

This makes your code cleaner, understandable and extendable.

It is important to remember: When working with inheritance, each derived class should satisfy the condition whether it “is a” base class or not. In the example above, Maths teacher is a Person, Footballer is a Person. You cannot have: Businessman is a Business.


Implementation of Inheritance in C++ Programming

class Person 
{
  ... .. ...
};

class MathsTeacher : public Person 
{
  ... .. ...
};

class Footballer : public Person
{
  .... .. ...
};

In the above example, class Person is a base class and classes MathsTeacher and Footballer are the derived from Person.

The derived class appears with the declaration of a class followed by a colon, the keyword public and the name of base class from which it is derived.

Since, MathsTeacher and Footballer are derived from Person, all data member and member function of Person can be accessible from them.


Example: Inheritance in C++ Programming

Create game characters using the concept of inheritance.

#include <iostream>
using namespace std;

class Person
{
     public:
        string profession;
        int age;

        Person(): profession("unemployed"), age(16) { }
        void display()
        {
             cout << "My profession is: " << profession << endl;
             cout << "My age is: " << age << endl;
             walk();
             talk();
        }
        void walk() { cout << "I can walk." << endl; }
        void talk() { cout << "I can talk." << endl; }
};

// MathsTeacher class is derived from base class Person.
class MathsTeacher : public Person
{
    public:
       void teachMaths() { cout << "I can teach Maths." << endl; }
};

// Footballer class is derived from base class Person.
class Footballer : public Person
{
    public:
       void playFootball() { cout << "I can play Football." << endl; }
};

int main()
{
     MathsTeacher teacher;
     teacher.profession = "Teacher";
     teacher.age = 23;
     teacher.display();
     teacher.teachMaths();

     Footballer footballer;
     footballer.profession = "Footballer";
     footballer.age = 19;
     footballer.display();
     footballer.playFootball();

     return 0;
}

Output

My profession is: Teacher
My age is: 23
I can walk.
I can talk.
I can teach Maths.
My profession is: Footballer
My age is: 19
I can walk.
I can talk.
I can play Football.

In this program, Person is a base class, while MathsTeacher and Footballer are derived from Person.

Person class has two data members – profession and age. It also has two member functions – walk() and talk().

Both MathsTeacher and Footballer can access all data members and member functions of Person.

However, MathsTeacher and Footballer have their own member functions as well: teachMaths() and playFootball() respectively. These functions are only accessed by their own class.

In the main() function, a new MathsTeacher object teacher is created.

Since, it has access to Person‘s data members, profession and age of teacher is set. This data is displayed using the display() function defined in the Person class. Also, the teachMaths() function is called, defined in the MathsTeacher class.

Likewise, a new Footballer object footballer is also created. It has access to Person‘s data members as well, which is displayed by invoking the display() function. The playFootball() function only accessible by the footballer is called then after.


Access specifiers in Inheritance

When creating a derived class from a base class, you can use different access specifiers to inherit the data members of the base class.

These can be public, protected or private.

In the above example, the base class Person has been inherited public-ly by MathsTeacher and Footballer.

Learn more about Public, Protected and Private Inheritance in C++.


Member Function Overriding in Inheritance

Suppose, base class and derived class have member functions with same name and arguments.

If you create an object of the derived class and try to access that member function, the member function in derived class is only invoked.

The member function of derived class overrides the member function of base class.

Learn more about Function overriding in C++.