Invoking Methods Using Base Class Type




This video tutorial explains how to invoke the methods using base class reference when we have a derived class object.
got confused? then you should watch this video to figure it out.
You are gonna learn different ways of invoking methods using the base class reference.

source code for this tutorial

#include <iostream>
#include <string>

using namespace std;

class Person{
public:
    void introduce(){
    cout <<"hey from person"<<endl;
    }
};

class Student : public Person{
public:
    void introduce(){
    cout <<"hey from student"<<endl;
    }
};

void whosThis(Person &p){
p.introduce();
}

int main()
{
    Student anil;
    anil.introduce();
    whosThis(anil);
    return 0;
}

 
Back To Top