Pages

Monday, 22 February 2016

Hierarchical Inheritance

# Write A Program To Show Hierarchical Inheritance….
# Set Your font type as Courier

class Animal(object) :
    def __init__(self,name) :
        self.name=name
    def speak(self) :
        print self.name,"says",self.sound()
class Cow(Animal) :
    def __init__(self,name) :
        Animal.__init__(self,name)
    def sound(self) :
        return"moo"
class Horse(Animal) :
    def __init__(self,name) :
        Animal.__init__(self,name)
    def sound(self) :
        return"neigh"
class Sheep(Animal) :
    def __init__(self,name) :
        Animal.__init__(self,name)
    def sound(self) :
        return"baaaaa"
h=Horse("Chetak")
h.speak()
c=Cow("Rambha")
c.speak()
s=Sheep("Mithi")

s.speak()