码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 42 - class and instantiate

时间:2019-10-01 20:44:33      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:har   ISE   person   ini   over   obj   ima   size   nim   

 

## 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

标签:har   ISE   person   ini   over   obj   ima   size   nim   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!