MENU
Question -

How encapsulation and abstraction are implemented in C++ language ? Explain with an example.



Answer -

Abstraction refers to the act of representing essential features without including the back-ground details or explanations.
Encapsulation is wrapping up of data and function together in a single unit.
We can say that encapsulation is way of achieving abstraction. Both these concepts are implemented in C++ in the form of a class. In a class data and function members are wrapped together. Only essential features are shown to the outside world in the form of member functions with public mode of accessibility. [1]
Example:     [1]

class Rectangle
 {
 int L, B;
 public: void Input() 
 {
      cin>>L>>B; 
 }
 void Output()
 {
 Cout<
 }
 };
In this example:
Data and member functions are together encapsulated
Only Input ( ) and Output ( ) functions are visible outside the class which can only can be accessed outside the class using objects of the same class – Abstraction

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×