1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Animal(): name = 'Amy' noise = "Grunt" size = "Large" color = "brown" hair = "covers body" def get_color(self): return self.color def make_noise(self): return self.noise
// Dog 繼承 Animal class Dog(Animal): name = 'Jon'
dog = Dog() dog.make_noise() dog.size = "small" dog.color = "black" dog.hair = "hairless"
|