Deriving One Class from Another - C++ Class

C++ examples for Class:Inheritance

Description

Deriving One Class from Another

Demo Code

#include <iostream>

using namespace std;

class Vehicle// w  w  w  .ja  v a 2  s.  c o  m
{
public:
    int count;

    void Drive()
    {
        cout << "Driving, driving, driving..." << endl;
    }
};

class Toyota : public Vehicle
{
public:
    void MeAndMyToyota()
    {
        cout << "Just me and my Toyota!" << endl;
    }
};

int main()
{
    Toyota MyCar;
    MyCar.MeAndMyToyota();
    MyCar.Drive();

    return 0;
}

Result


Related Tutorials