[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
multiple inheritance
Example in C++:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
multiple inheritance
Multiple inheritance
Multiple inheritance is a term from object oriented programming. In every modern object oriented programming language, a class can inherit from another class. Multiple inheritance simply means that a class can inherit from more than one class. An example of a programming language where this is possible is C++. In Java, it is not possible, but in most situations one can use interfaces instead to get the same thing in a different way. More specifically, in Java a class can inherit from only one class, but can ''implement'' multiple interfaces.Example in C++:
class A
{
public:
int GetA() { return a; }
void SetA(int n) { a = n; }
private:
int a;
};
class B
{
public:
int GetB() { return b; }
void SetB(int n) { b = n; }
private:
int b;
};
class C: public A, public B
{
public:
int GetSum() { return GetA()+GetB(); }
};
int main()
{
C c;
c.SetA(5);
c.SetB(7);
cout << c.GetSum() << endl; // is 12
}
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
