习题42 对象, 类和从属关系

学习目标:

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

你可能感兴趣的:(python,python)