class dog:
def bark(self):
print "WOOF!"
def setAge(self,age):
self.age=age
def setWeight(self,weight):
self.weight=weight
def setColor(self,color):
self.color=color
def getAge(self):
return self.age
def getWeight(self):
return self.weight
def getColor(self):
return self.color
if __name__=='__main__':
fido=dog()
fido.setAge(3)
fido.setWeight(15)
fido.setColor("brown")
print "Fido is a",fido.getColor()," dog"
print "Fido is ",fido.getAge()," years old"
print "Fido Weighs ",fido.getWeight()," pounds"
fido.bark()
class dog:
def bark(self):
print "WOOF!"
def setValues(self,age,weight,color):
self.age=age
self.weight=weight
self.color=color
def getAge(self):
return self.age
def getWeight(self):
return self.weight
def getColor(self):
return self.color
if __name__=='__main__':
fido=dog()
fido.setValues(3,15,"brown")
poonch=dog()
poonch.setValues(4,18,"gray")
print "Fido is a",fido.getColor()," dog"
print "Fido is ",fido.getAge()," years old"
print "Fido Weighs ",fido.getWeight()," pounds"
fido.bark()
print "Poonch is ",poonch.getAge()," years old ",poonch.getColor()," dog who weighs ",poonch.getWeight()," pounds",poonch.bark()
class dog:
def __init__(self,age,weight,color):
self.age=age
self.weight=weight
self.color=color
def bark(self):
print "WOOF!"
def getAge(self):
return self.age
def getWeight(self):
return self.weight
def getColor(self):
return self.color
def __del__(self):
print "Object destroyed"
if __name__=='__main__':
fido=dog(3,15,"brown")
poonch=dog(4,18,"gray")
print "Fido is a",fido.getColor()," dog"
print "Fido is ",fido.getAge()," years old"
print "Fido Weighs ",fido.getWeight()," pounds"
fido.bark()
print "Poonch is ",poonch.getAge()," years old ",poonch.getColor()," dog who weighs ",poonch.getWeight()," pounds",poonch.bark()
del fido
del poonch
class dog:
def __init__(self,age=1,weight=2,color="black"):
self.age=age
self.weight=weight
self.color=color
def bark(self,noise):
print noise
def getAge(self):
return self.age
def getWeight(self):
return self.weight
def getColor(self):
return self.color
def __del__(self):
print "Object destroyed"
if __name__=='__main__':
fido=dog(3,15,"brown")
poonch=dog(4,18,"gray")
rex=dog()
sammy=dog(2,6,"white")
print "Fido is a",fido.getColor()," dog"
print "Fido is ",fido.getAge()," years old"
print "Fido Weighs ",fido.getWeight()," pounds"
fido.bark("WOOF!")
print "Poonch is ",poonch.getAge()," years old ",poonch.getColor()," dog who weighs ",poonch.getWeight()," pounds",poonch.bark("WOOF!")
print "Rex is ",rex.getAge()," years old ",rex.getColor()," dog who weighs ",rex.getWeight()," pounds",rex.bark("GRRR!")
print "Sammy is ",sammy.getAge()," years old ",sammy.getColor()," dog who weighs ",sammy.getWeight()," pounds",sammy.bark("BOWOW!")
del fido
del poonch
del rex
del sammy
class Polygon:
weight=0
height=0
def setValues(self,w,h):
self.weight=w
self.height=h
class Rectangle(Polygon):
def area(self):
return self.weight*self.height
class Triangle(Polygon):
def area(self):
return (self.weight*self.height)/2
rect=Rectangle()
trgl=Triangle()
rect.setValues(4,5)
trgl.setValues(4,5)
print "Rectangle Area:",rect.area()
print "Triangle Area:",trgl.area()
class Parent:
def __init__(self):
print "Default Parent Constructor Called"
def __init__(self,a):
print "Overloaded Parent Constructor Called"
class Daughter(Parent):
def __init__(self):
print "Derived Daughter class default constructor called"
class Son(Parent):
def __init__(self,a):
Parent.__init__(self,a)
print "Derived Son class overloaded constructor called"
emma=Daughter()
andrew=Son(0)
class Man:
def Speak(self, msg="Hello"):
print " ",msg
class Hombre(Man):
def Speak(self,msg):
print msg
henry=Man()
enrique=Hombre()
henry.Speak()
henry.Speak("It's a beautiful evening.")
enrique.Speak("Hola!")
enrique.Speak("Es una trade hermosa")