CSC/ECE 517 Fall 2011/ch1 1i lj
CSC/ECE 517 Fall 2010/ch1 1i lj
Introduction
Overriden Method
Method overriding[1], in object oriented programming, is a language feature that allows a subclass to provide a specific implementation of a method that is already provided by one of its superclasses. The implementation in the subclass overrides (replaces) the implementation in the superclass.
Ruby
Java
C++
In native C++, a derived class function having the same name and parameters as a base class virtual function will *always* override it. In C++/CLI you have the option of using the new contextual keyword to specify whether you want to override a base class function or hide it. Example:
ref class Base { public: virtual void Goo() { Show("Base::Goo"); } virtual void Boo() { Show("Base::Boo"); } virtual void Doo() { Show("Base::Doo"); } }; ref class Derived : Base { public: //Overrides Base::Goo virtual void Goo() { Show("Derived::Goo"); } //Overrides Base::Boo as above virtual void Boo() = Base::Boo { Show("Derived::Boo"); } //Hides Base::Doo virtual void Doo() new { Show("Derived::Doo"); } };