Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 13, 2018 22:19
Show Gist options
  • Save pknowledge/f5d3aff5468eb3846eea2752f525b4df to your computer and use it in GitHub Desktop.
Save pknowledge/f5d3aff5468eb3846eea2752f525b4df to your computer and use it in GitHub Desktop.
rectangle_Encapsulation.py
class Rectangle:
def __init__(self, height, width):
self.__height = height
self.__width = width
def set_height(self, height):
self.__height = height
def get_height(self):
return self.__height
def set_width(self, width):
self.__width = width
def get_width(self):
return self.__width
def area(self):
return self.__height * self.__width
rect1 = Rectangle(20, 60)
rect2 = Rectangle(50, 40)
print(rect1.area())
print(rect2.area())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment