Anurag
Anurag

Reputation: 11

Doing Overriding of function in base class by same name function in the child class of its child class(multiple inheritance)?

Consider the following, only program body, syntax not correct:

class super
{
  func1();//the method which is to be be overridden
}
class sub1 extends super
{
  func1();
}
class sub2 extends sub1
{
  func1();
}

class Main
{
  main()
}

Upvotes: 1

Views: 142

Answers (2)

Arun
Arun

Reputation: 20393

Multiple Inheritance is the scenario when one class inherits from multiple classes. Wiki

Example: class D derives from both class B1 and class B2

class D : public B1, public B2 {
};

Your example, as itowlson already pointed out, is two levels of single inheritance, which is not same multiple inheritance.

Upvotes: 1

Kobi
Kobi

Reputation: 138127

  1. This is very possible and common use on inheritance. However, for this to work well, some languages require additional keywords (new or virtual, depending on your intentions)
  2. This does not constitute multiple inheritance. multiple inheritance is when one class is deriving many base classes.

Upvotes: 1

Related Questions