Code About Us Tutorial


  Inheritance
    What is Inheritance?
    Creating a Derived Class
    Creating an Object
    Simple Inheritance
    Overloading Derived Classes
    Dominating Member Functions
    Polymorphism & Virtual Functions


   
 

Home > Inheritance > Creating a Derived Class

November 27, 2009 5:01 am

   

Creating a Derived Class

Here is an example of a derived class of Reptile. The syntax for making a derived class is as follows:

 

 
class name of class: public/private name of base class
{
//everything else is the same as making a regular class

};

For now just use the public keyword, I’ll explain how the private keyword works later.

 

 
//superset, derived class from base class(reptile)

class Lizard: public Reptile { public: Lizard(){}; ~Lizard(){};

void setAge(int age) { itsAge = age;} int getAge() { return itsAge;}

void RegenerateTale() const { cout<<"Regenerating Tale....n";} void RunFromPredator() const { cout <<"Running...n";} protected: int itsAge; };

Please Rate this Code:


    Comments for: Creating a Derived Class
  There are NO user contributed comments for Creating a Derived Class.



Add Comment:
Name:
Email:


 «3» THINKQUEST TEAM C0111571 © 2001. All Rights Reserved.