Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ Polymorphism

// Base class
class Animal {
  public:
    void animalSound() {
    cout << "The animal makes a sound 
" ;
  }
};

// Derived class
class Pig : public Animal {
  public:
    void animalSound() {
    cout << "The pig says: wee wee 
" ;
  }
};

// Derived class
class Dog : public Animal {
  public:
    void animalSound() {
    cout << "The dog says: bow wow 
" ;
  }
};
Source by www.mygreatlearning.com #
 
PREVIOUS NEXT
Tagged: #Polymorphism
ADD COMMENT
Topic
Name
7+9 =