0

What is overriding in c++...?

answer

11th Sep 2017, 4:06 PM
Mayank Patel
Mayank Patel - avatar
2 Answers
+ 9
In any object-oriented programming language, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.
11th Sep 2017, 4:48 PM
P R
P R - avatar
+ 1
consider class Base { public: void foo(){ std::cout << "Hello!"; } }; and two subclasses class Derived1 : Base { }; class Derived2 : Base { public: void foo(){ std::cout << "haha, I'm overriding Base::foo"; } }; Now, if you had Derived1 first; Derived2 second; first.foo() will print "Hello", because it inherited the method of the base class. second.foo() will print "haha, I'm overriding Base::foo", because we added a method with the same name, foo, to it, that overrides the method it got from the base class.
11th Sep 2017, 4:18 PM
Schindlabua
Schindlabua - avatar