Write a program for function overriding in c++

Que- make a program on Enter 2 numbers by function overriding?

#include<iostream>
using namespace std;

class krishna
{
public:
    int a,b;
    virtual void getdata ()
    {   cout<<"enter two numbers :- ";
        cin>>a>>b;
    }
    virtual void display ()
    {
        cout<<"enter numbers are :-"<<a<<" "<<b<<endl;
    }
};
class second: public krishna
{
public:
};

int main()
{
    second on;
    krishna *d;
    on.getdata();
    on.display();
    d= &on;
    d->getdata();
    d->display ();

    return 0;

}

Result:-



Post a Comment

Previous Post Next Post