0% found this document useful (0 votes)
3 views

Overloading,Overriding,Virtual

The document contains three examples of C++ programming concepts: function overloading, function overriding, and virtual functions. The first example demonstrates function overloading with different parameter types in the 'dot' and 'scholar' classes. The second example shows function overriding where the 'scholar' class overrides the 'print' method of the 'dot' class, and the third example illustrates the use of virtual functions to achieve polymorphism.

Uploaded by

Abhinav Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Overloading,Overriding,Virtual

The document contains three examples of C++ programming concepts: function overloading, function overriding, and virtual functions. The first example demonstrates function overloading with different parameter types in the 'dot' and 'scholar' classes. The second example shows function overriding where the 'scholar' class overrides the 'print' method of the 'dot' class, and the third example illustrates the use of virtual functions to achieve polymorphism.

Uploaded by

Abhinav Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

/*EG_of_function_overloading*/

#include<iostream>

using namespace std;

class dot{

public:

void print(int x){

cout<<"DotNetTrick was established in"<<x<<endl;

};

class scholar:dot{

public:

void print(string name){

cout<<"ScholarHat was found by the DotNetTricks founder:"<<name<<endl;

};

int main(){

dot a;

scholar s;

a.print(2015);

s.print("Shailendra Chuhan");
return 0;

/*EG_of_function_overriding*/

#include<iostream>

using namespace std;

class dot{

public:

void print(){

cout<<"Welcome to DotNetTrick"<<endl;

};

class scholar:public dot{

public:

void print(){

cout<<" Welcome to schoolarhat"<<endl;

};
int main(){

scholar obj;

obj.print();

return 0;

/*EG_of_virtual_function*/

#include<iostream>

using namespace std;

class dot{

public:

virtual void print(){

cout<<"Welcome to DotNetTrick"<<endl;

};

class scholar:public dot{

public:

void print(){
cout<<" Welcome to schoolarhat"<<endl;

};

int main(){

scholar sobj;

dot*ptr=&sobj;

ptr->print();

return 0;

You might also like