擅长:python、mysql、java
<p>子类的<code>__init__</code>方法的签名当然可以与其超类不同。它只需要调用其超类的<code>__init__</code>方法,该方法需要:</p>
<pre><code>class Vehicle:
def __init__(self, colour, wheels, size):
self.colour = colour
self.wheels = wheels
self.size = size
class Car(Vehicle):
def __init__(self, colour, wheels):
super().__init__(colour, wheels, 'small')
print(Car('white', 4).size)
</code></pre>
<p>这将输出:</p>
<pre><code>small
</code></pre>