Explain the scope of private member of a class with one example-00364

Online Quiz This subjective question is related to the book/course vu cs201 Introduction to Programming. It can also be found in vu cs201 Mid Term Solved Past Paper No. 6.

Question 1: Explain the scope of private member of a class with one example.
Answer:

The scope of private data member of a class is that, only an access is allowed within the class. Only member function of class can access and modify the value of data member value. Derived class or class instance/object can?t directly access. Data Member will created for each separate object in the memory and will eliminated when object will be destroy. Object could be destroy by calling its destructor. Example:

Class arthimetic {
Private:
int a,b;
Public:
Add() {
A+b; // direct access by member function Correct Access
}
};
Int main() {
Arthimetic c1;
C1.a=4; // is illegal access to class private data member error will generate by compiler
}

Choose an organization

Theme Customizer

Gaussian Texture



Gradient Background