Wednesday, July 25, 2018

Multiple Inheritance, Diamond problem


Programming languages like Java and Swift does not give Multiple Inheritance support cause of Diamond problem that may occur.

Diamond Problem:


          A
         /   \
       B     C
        \      /
           D

Class B & Class C inherits from Class A

A -> B & C

Class D inherits from Class B and Class C

B & C -> D

What If you have a overridden method in both class B & C from super class A?

As D is derived from B & C, There is problem when that method is called using D’s object.

a.method()

b.method()  //overridden
c.method() //overridden

Now If I call,

d.method()

Which one gets called? 

B’s method() or C’s  method()  ???

This is the Diamond problem.

That’s the reason, Multiple Inheritance is not supported in Swift.

If you try you end up with below compile time error.




Hope this post is useful. Feel free to comment incase of any queries.

3 comments:


  1. This article is very much helpful and i hope this will be an useful information for the needed one.Keep on updating these kinds of informative things ios app development course

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Casinos with Slots for free - No deposit required
    Play for free slots from the best casino sites 점심 메뉴 룰렛 in the world. 룰렛돌리기 No deposit bonuses and welcome offers make no 벳 365 우회 주소 deposit required for you to play the 인디언 포커 games 슬롯 가입 쿠폰 on your

    ReplyDelete