Python Classroom Series – 03/Sept/2021

Adding a Method in the Child Class

  • Child class can add methods that are not present in parent class
  • Refer Here forthe examples done in the class
  • For properties
class Student:
    def __init__(self,name) -> None:
        self.__name = name

    def name(self):
        return self.__name

    def name(self, value):
        self.__name = value

class Circle():
    def __init__(self, radius) -> None:
        self.__radius = radius

    def diameter(self):
        return 2 * self.__radius

    def area(self):
        import math
        return math.pi * self.__radius ** 2

s1 = Student('Ram')
print( = "Shyam"

c1 = Circle(10)

  • Name Mangling for privacy:
    • If you want hide your attribute begin the member name with two underscores Preview

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin