首页 > 其他 > 详细

Exercise 42 - class and instantiate

时间:2019-10-01 19:54:11      阅读:88      评论:0      收藏:0      [点我收藏+]

 

## Animal is-a object (yes, sort of confusing) look at the extra credit
class Animal(object):
    pass

## ??
class Dog(Animal):
    
    def __init__(self, name):
        ## ??
        self.name = name

## ??
class Cat(Animal):

    def __init__(self, name):
        ## ??
        self.name = name
        
## ??
class Person(object):

    def __init__(self, name):
        ## ??
        self.name = name
        
        ## Person has-a pet of some kind
        self.pet = None
        
## ??
class Employee(Person):

    def __init__(self, name, salary):
        ## ?? hmm what is this strange magic?
        super(Employee, self).__init__(name)
        ## ??
        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 = Person("Mary")

## ??
mary.pet = satan

## ??
frank = Employee("Frank", 120000)

## ??
frank.pet = rover

## ??
flipper = Fish()

## ??
crouse = Salmon

## ??
harry = Halibut() 

 

2019-10-01

23:51:14

Exercise 42 - class and instantiate

原文:https://www.cnblogs.com/petitherisson/p/11615821.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!