Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Encapsulation in Python using public members

# illustrating public members & public access modifier 
class pub_mod:
    # constructor
    def __init__(self, name, age):
        self.name = name;
        self.age = age;
 
    def Age(self): 
        # accessing public data member 
        print("Age: ", self.age)
# creating object 
obj = pub_mod("Jason", 35);
# accessing public data member 
print("Name: ", obj.name)  
# calling public member function of the class 
obj.Age()
Source by www.scaler.com #
 
PREVIOUS NEXT
Tagged: #Encapsulation #Python #public #members
ADD COMMENT
Topic
Name
5+5 =