C++ Program For Overloading vs Overriding

Free C++ course with real-time projects Start Now!!

Program 1

// Program for method overloading and Overriding
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Base
{
     public:
     void display()
     {
        cout<<"\nDispaly of Base  without Parameter";
     }
    
};
class Derived:public Base   //Method Overriding
{
    public:
     void display()
     {
        cout<<"\nDispaly of Derived  without Parameter:";
        cout<<"hello Hi Bye";
     }
     void display(int n)
     {
        cout<<"\nDispaly of Derived  with Parameter: "<<n;
     }

};
int main()
{
   clrscr();
   Base B;
//    Derived D;
//    D.display();
//    D.display(100);    

}

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *