+ 2
overloading is used when we want a function to do diffrent things depending on what is passed to that function. in simple words, overloading provides polymorphism. same function with different functionalities depending on parameters. e.g area(int l, int b) // area of rectangle { return l*b; } area(int side) // area of square { return side*side; } overriding is totally different. in this we overrides the base class function in derive class and add some new functionality. derived class function is called instead of base class function when a object of base class is created. this is called overriding. e.g public class base{ public: void func(){ cout<<"Hello"; } public class derive: public base{ public: void func(){ // override func of derive class cout<<"world"; } }
30th Dec 2016, 9:11 AM
Ravi Kumar
Ravi Kumar - avatar