Sharp Tutorial
overriding in C++

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

introduction to c++

  • C++ Home
  • Introduction to C++
  • History features
  • Sample Programs
  • cout , cin , endl
  • Data type and Operators
  • if else in c++
  • loop in c++

Oops in C++

  • Object / Class
  • Constructor
  • Function & Constructor Overloading
  • Inheritance
  • Overriding

Advanced C++

  • Strings in C++
  • Exception Handling
  • Special Functions
  • C++ Programs

overriding in c++

When sub class as the same name function as super class then sub class function override the base class function and property is known as function overriding.

Function overriding is the way to achieve runtime polymorphism.

Function Overriding example

#include<iostream>
using namespace std;
class A
{
public:
void display()
{
cout<<"Base class display function"<<endl;
}
};


class B : public A
{
public:
void display()
{
cout<<"Derived Class display function";
}
};
int main()
{
A a1;
a1.display();
B b1;
b1.display(); // Here B class function overrides the its super class function
return 0;
}

 

Output of the above program is as follows.

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial