class Rectangle:
length = 0
width = 0
def getData(self, x, y):
self.length = x
self.width = y
def rectArea(self):
area = self.length * self.width
return area
rect1 = Rectangle()
rect1.length = 15
rect1.width = 10
rect2 = Rectangle()
area1 = rect1.length*rect1.width
rect2.getData(20,12)
area2 = rect2.rectArea()
print "Area1 = ", area1
print "Area2 = ", area2
class Rectangle:
length = 0
width = 0
def __init__(self, x=0, y=0):
self.length = x
self.width = y
def rectArea(self):
return self.length * self.width
rect1 = Rectangle(15, 10)
area1 = rect1.rectArea()
print "Area1 = ", area1
#there are no static methods in Python, we will use normal methods instead
class MathOperations:
def mul(self, x, y):
return x*y
def divide(self, x, y):
return x/y
obj = MathOperations()
a = obj.mul(4.0,5.0)
b = obj.divide(a,2.0)
print "b = ", b
class Nesting:
m = 0
n = 0
def __init__(self, x, y):
self.m = x
self.n = y
def largest(self):
if(self.m>=self.n):
return self.m
else:
return self.n
def display(self):
large = self.largest()
print "Largest Value: ", large
nest = Nesting(50, 40)
nest.display()
class Room(object):
def __init__(self, x, y):
self.length = x
self.breadth = y
def area(self):
return self.length*self.breadth
class BedRoom(Room):
height = 0
def __init__(self, x, y, z):
Room.__init__(self, x, y)
self.height = z
def volume(self):
return self.length*self.breadth*self.height
room1 = BedRoom(14, 12, 10)
area1 = room1.area()
volume1 = room1.volume()
print "Area = ", area1
print "Volume = ", volume1
class Super(object):
x = 0
def __init__(self, x):
self.x = x
def display(self):
print "Super x = ", self.x
class Sub(Super):
y = 0
def __init__(self, x, y):
Super.__init__(self, x)
self.y = y
def display(self):
print "Super x = ", self.x
print "Sub y = ", self.y
s1 = Sub(100, 200)
s1.display()
class Exampleprg:
def __init__(self, *args):
for arg in args:
print "Hello ", arg
e = Exampleprg("John", "David", "Suhel")