0% found this document useful (0 votes)
2 views1 page

Understanding Encapsulation in OOP

Encapsulation is a principle in object-oriented programming that combines data and code into a single unit while restricting direct access to certain components. This helps prevent accidental interference and misuse of the data. An example in C++ demonstrates encapsulation through a 'Student' class with private age data and public methods to set and get the age.

Uploaded by

azazarfin54
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Understanding Encapsulation in OOP

Encapsulation is a principle in object-oriented programming that combines data and code into a single unit while restricting direct access to certain components. This helps prevent accidental interference and misuse of the data. An example in C++ demonstrates encapsulation through a 'Student' class with private age data and public methods to set and get the age.

Uploaded by

azazarfin54
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Encapsulation

Encapsulation is the concept of wrapping data and code together as a single unit.

In object-oriented programming, it restricts direct access to some of an object's components,

which is a means of preventing accidental interference and misuse of the data.

Example in C++:

class Student {

private:

int age;

public:

void setAge(int a) {

age = a;

int getAge() {

return age;

};

You might also like