Method (computer Science) - Virtual Methods

Virtual methods are the means by which a class object can achieve polymorphic behavior. Non-virtual methods, or regular methods, are those which do not participate in polymorphism.

C++ Example:

#include #include class Super { public: virtual void iAm { std::cout << "I'm the super class!\n"; } } class Sub : public Super { public: void iAm { std::cout << "I'm the subclass!\n"; } } int main { std::unique_ptr inst1(new Super); std::unique_ptr inst2(new Sub); inst1->iAm; // calls Super::iAm inst2->iAm; // calls Sub::iAm }

Read more about this topic:  Method (computer Science)

Famous quotes containing the words virtual and/or methods:

    Tragedy dramatizes human life as potentiality and fulfillment. Its virtual future, or Destiny, is therefore quite different from that created in comedy. Comic Destiny is Fortune—what the world will bring, and the man will take or miss, encounter or escape; tragic Destiny is what the man brings, and the world will demand of him. That is his Fate.
    Susanne K. Langer (1895–1985)

    The philosopher is in advance of his age even in the outward form of his life. He is not fed, sheltered, clothed, warmed, like his contemporaries. How can a man be a philosopher and not maintain his vital heat by better methods than other men?
    Henry David Thoreau (1817–1862)