class Animal(object):
def __init__(self):
print "I'm a animal."
class Dog(Animal):
def __init__(self, name):
self.name = name
class Cat(Animal):
def __init__(self, name):
self.name= name
class Ant(Animal):
pass
class Person(object):
def __init__(self, name):
self.name = name
self.pet = None
class Employee(Person):
def __init__(self, name, salary):
super(Employee, self).__init__(name)
self.salary = salary
class Fish(object):
def __init__(self, name):
self.name = name
print "I'm a fish , named %s " % name
def EatTimePerDay(count):
print "I need eat %d times per day." % count
class Salmon(Fish):
def __init__(self, name):
print "I'm a salmon, name %s." % name
super(Salmon, self).__init__(name)
class Halibut(Fish):
def __init__(self, name):
print "I'm a Halibut, name %s." % name
# super(Halibut, self).__init__(name)
self.name = name
rover = Dog("Rover")
satan = Cat("Satan")
mary = Person("Mary")
mary.pet = satan
print "Her name is %s, and has pet - %s " % (mary.name, mary.pet.name)
frank = Employee("Frank", 120000)
frank.pet = rover
print "His name is %s, and his salary is %d, and His pet is %s. \n\n" % (frank.name, frank.salary, frank.pet.name)
sansa = Ant()
print "---------"
flipper = Fish("aa")
print "---------"
crouse = Salmon("bb")
print "---------"
harry = Halibut("cc")
结果: