Inheritance/Multiple

From Rosetta Code
Revision as of 16:54, 27 April 2008 by Ce (talk | contribs) (New task, C++ code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Inheritance/Multiple
You are encouraged to solve this task according to the task description, using any language you may know.

Multiple inheritance allows to specify that one class is a subclass of several other classes. Some languages allow multiple inheritance for arbitrary classes, others restrict it to interfaces, some don't allow it at all.

Write two classes (or interfaces) Camera and MobilePhone, then write a class CameraPhone which is both a Camera and a MobilePhone.

There is no need to implement any functions for those classes.

C++

<cpp> class Camera {

 // ...

};

class MobilePhone {

 // ...

};

class CameraPhone:

 public Camera,
 public MobilePhone

{

 // ...

}; </cpp>