Definition of a derived class
The syntax for defining a derived class
1. When derived from a single base class
//base class
class base
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
//derived class
class derived : private/protected/public base
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
Example:
class base
{
};
class derived:base //by default it is private
{
};
2. When derived from multiple base classes
class base1
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
class base2
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
class derived:private/protected/public base1,private/protected/public base2
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};