Question:

How would you define a protected member in a Python class?

Answer:

All the members of a class in Python are public by default. You don’t need to define an access specifier for members of class. By adding ‘_’ as a prefix to the member of a class, by convetion you are telling others please don’t this object, if you are not a subclass the respective class.
Eg: class Person:
empid = None
_salary = None #salary is a protected member & it can accessible by the subclasses of Person
….


Keywords:

© 2017 QuizBucket.org