Advertisements
Advertisements
प्रश्न
Write a class with two private class variables and print the sum using a method.
टिप्पणी लिखिए
उत्तर
class Sample:
def_init_(self,n1,n2):
self._n1=n1
self._n2=n2
def display(self):
print(“class variable 1:”, self._n1)
print(“class variable 2:”, self._n2)
print(“sum self._n1 + self._n2)
s = sample(10, 20)
s.display( )
Output:
class variable 1: 10
class variable 2: 20
sum: 30
shaalaa.com
Public and Private Data Members
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?