ex2.py
## Animal is-a object(yes,sort of confusing) look at extra cerdit
class Animal(object):
pass
## ??创建Dog类,是Animal的一种
class Dog(Animal):
def __init__(self, name):
## ??
self.name = name
## ??
class Cat(Animal):
def __inti__(self, name):
## ??
self.name = name
## ??
class Person(boject):
def __inti__(self, name):
## ??
self.name = name
##Person has-a pet of some kind
slef.pet = None
## ??
class Employee(Person):
def__inti__(self, name, salary):
## ?? hmm what is this strange magic?
super(Employee, slef).__inti__(name)
## ??super() 来调用父类的__init__ 构造方法
self.salary = salary
## ??
class Fish(object):
pass
## ??
class Salmon(Fish):
pass
## ??
class Halibut(Fish):
pass
## rover is-a Dog
rover = Dog("Rover")
## ??
satan = Cat("Satan")
##??
mary = Preson("Mary")
## ??
mary.pet = Satan
## ??
frank = Employee("Frank", 120000)
## ??
frank.pet = rover
## ??
flipper = Fish()
## ??
crouse = Salmon()
## ??
harry = Halibut()
2023.5.16
ex42.py