+ 1

Output of inheritance Question no. 10

https://www.codementor.io/sheena/essential-JUMP_LINK__&&__python__&&__JUMP_LINK-interview-questions-du107ozr6 I am not able to understand how inheritance work in this Question 10 (please follow this link). d.go() is not clear..Though we can check it by using D.mro() and I think d.go() will output --- go A go! go B go! go A go! go C go! go D go! ( However correct output is - go A go! go C go! go B go! go D go! ) As class D inherits B and C..so first go() method of D will run then go() of B and then go() of C.. In go() of D there is super(), so it will jump to class B go() method and at that there is also super() then it will go to class A..so first output is----- go A go! then go B go! then it will go to Class C and again there is super() then it will go to class A and output -- go A go! then go C go! Then come back to Class D , remaining print statement will be printed -- go D go! what is wrong in this explanation ... and I usually see super.go() but in this article they used super(B,self).go() what does this mean? Thanks

4th Sep 2018, 3:59 PM
đŸŒ·â“â“€đ”č𝓝ⓐ â“€â“—đ”žâ“đŸŒ·
đŸŒ·â“â“€đ”č𝓝ⓐ â“€â“—đ”žâ“đŸŒ· - avatar
2 Answers
0
syntax correspond to python 2.xx Details: return super(Derived, self).m() Derived refers to the class whose parent class contains the definition of the m method that we wish to use. In contrast, self refers to the instance on which we would like to call that method.
7th Sep 2018, 4:05 AM
Miguel Angel Acosta
Miguel Angel Acosta - avatar
6th Apr 2020, 5:57 AM
rahul kumar
rahul kumar - avatar