擅长:python、mysql、java
<p>调用时,需要将self从继承类的display方法传递给Mainclass.display()方法。所以你的代码变成:</p>
<pre><code>class Mainclass(object):
"""
Class to test the inheritance
"""
def __init__(self,somevalue):
self.somevalue = somevalue
def display(self):
print(self.somevalue)
class Inherited(Mainclass):
"""
Inherited class from the Main Class
"""
def display(self):
print("**********")
Mainclass.display(self)
print("**********")
c = Inherited(100)
c.display()
</code></pre>
<p>希望这有帮助!:)</p>