擅长:python、mysql、java
<p>你没有调用方法。当您要调用每个方法时,在它们后面添加<code>()</code>。否则,解释器将只返回对象的类型</p>
<pre><code>parentOBJ.helloWorld()
childOBJ.helloWorld()
childOBJ.helloWorld2()
</code></pre>
<p>但是,您还必须修复类定义:</p>
<pre><code>class parent(object): # All classes should inherit from the object-class
def helloWorld(self): # unless you have other arguments besides self, remove the comma.
print("hello World1")
class child(parent):
def helloWorld2(self):
print("hello World2")
</code></pre>
<p>示例:</p>
<pre><code>>>> parentOBJ = parent()
>>> childOBJ = child()
>>> parentOBJ.helloWorld()
hello World1
>>> childOBJ.helloWorld()
hello World1
>>> childOBJ.helloWorld2()
hello World2
</code></pre>