Write a program in python: Create a class Box and found area of rectangle also use function definition inside class


  • Define a class
  • Define method to set value
  • Define init method to setvalue
  • Define function to return area

__Author_="Simulation-Hub"
#class start
class Box:
num=1
leng=0
wir=0
def __init__(self,l,w):
self.leng=l
self.wir=w
Box.num=Box.num+1
print("Class Varible :",Box.num)
def printData(self):
print("Length of Box is:",self.leng)
print("Wid of Box is: ",self.wir)
def Area(self):
print("Area of Box: ",(self.leng*self.wir))
Box.num=Box.num+1
print("Class variable :",Box.num)
#class end
#object of class
B=Box(4,2)
B.printData()
B.Area()
Class Varible : 2
Length of Box is: 4
Wid of Box is:  2
Area of Box:  8
Class variable : 3

0 Comments