#Instace Class and Static Method in Python
class Test:
#Class variable
i = 0
#Instance Variable
#Instance Method
def __init__(self,c):
Test.i = Test.i + 1
self.j=c
def printValObj(self):
print(self.j)
@classmethod
def printValCls(self,a):
print("Class : ",self.i)
print("Object : ",a.j)
@staticmethod
def getPI():
T = Test.i * 2
Test.i = T
return T
t1 = Test(10)
t1.printValObj()
Test.printValCls(t1)
print(Test.getPI())
print(t1.getPI())
t2 = Test(10)
print(t1.getPI())
class Test:
#Class variable
i = 0
#Instance Variable
#Instance Method
def __init__(self,c):
Test.i = Test.i + 1
self.j=c
def printValObj(self):
print(self.j)
@classmethod
def printValCls(self,a):
print("Class : ",self.i)
print("Object : ",a.j)
@staticmethod
def getPI():
T = Test.i * 2
Test.i = T
return T
t1 = Test(10)
t1.printValObj()
Test.printValCls(t1)
print(Test.getPI())
print(t1.getPI())
t2 = Test(10)
print(t1.getPI())
Comments
Post a Comment