Skip to content

Latest commit

 

History

History

01_Mar3

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Mar 3

Polymorphism

1. Overloading

add(int a, int b);
add(float a, float b);

//function call
add(1,2);
add(1.2,2.3);

2. Overriding

The process of redefining the existing data members present in superClass from a base class using inheritance.

superClass{
    methodOne() {
        cout << "Hi";
    }
};

subClass: public superClass{
    methodOne(){
        cout << "Hello";
    }
};
    graphTD;
        Polymorphism-->CompileTime;
        Polymorphism-->Runtime;
        CompileTime-->FunctionOverloading ;
        CompileTime-->OperatorOverloading;
        Runtime-->VirtualFunction;
        Runtime-->FunctionOverriding;
Loading
#include <iostream>
using namespace std;
  
class Parent {
public:
     void hello(){
        cout << "Base Function" << endl;
    }
};
  
class Child : public Parent {
public:
    void hello(){
        cout << "Derived Function" << endl;
    }
};
  
int main() {
    Child he;
    he.hello();

    return 0;
}