Week No 8
Week No 8
Programming
1
The members of a class which are declared protected are only accessible
to a class derived from it. Data members of a class are declared
protected by adding a single underscore ‘_’ symbol before the data
member of that class.
8 Access Modifier Protected
9 Access Modifier Protected
In the above program, _name, _roll and _branch are protected data
members and _displayRollAndBranch() method is a protected
method of the super class Student. The displayDetails() method is a
public member function of the class Geek which is derived from
the Student class, the displayDetails() method in Geek class
accesses the protected data members of the Student class.
10 Access Modifier Private
The members of a class which are declared private are accessible within
the class only, private access modifier is the most secure access modifier.
Data members of a class are declared private by adding a double
underscore ‘__’ symbol before the data member of that class.
11 Access Modifier Private
12 Access Modifier Private