Data Abstraction in C++

Estudies4you
Q7. List the reasons to declare static member variables outside the class.
Answer:

There are some reasons to declare static. member variables outside the class. They are as follows:
  1. The memory is allocated separately to static member variables irrespective of objects.
  2. The static member variables must be initialized with a value to avoid linker errors.
  3. For the static member variables, memory is allocated at most one time.
  4. The memory is allocated only once for static variables and the entire class objects will use the common static variable
Q8. Write a short note on data abstraction.
Answer:

An abstraction is a process of showing relevant details and hiding irrelevant details from the user i.e., the implementation details are completely hidden from the user.
It gives the representation of real-world entities thereby showing only important attributes from the set of attributes.
To form groups from the set of attributes by using abstraction, then while forming the groups, the common attributes have been neglected hence; abstraction reduces the group complexity by simplifying its elements.
There are two types of abstraction. Those are,
(i) Process abstraction
(ii) Data abstraction.

Q9. What is ADT?
Answer:

Abstract Data Type (ADT) is a data type that allows the programmer to use it without concentrating on the details of its implementation.
A class can be treated as an abstract data type by separating its specifications from the implementation of its operations.
This separation between the specifications and the implementation-can be obtained by,
(i) Considering and placing all the member variables in the private section of the class.
(ii) Placing all the needed operations in the public section and describing the ways of using these member functions.
(iii) Considering all the helping functions as private member functions and placing them in private section of the class.

Q10. Discuss about Information Hiding.
Answer:

Information hiding means hiding the class member variables and member functions. The process of hiding data involves hiding a class by declaring the data members and member functions within a “private” section. Mostly member variables are declared as private and member functions as public. The data members that are declared as private cannot be accessed outside the class. Thereby, security is provided to the data. These private members are accessed by using public member functions: Generally, private and protected are the keywords that are used to provide security. The data that is encapsulated can also be called as ADT (Abstract Data Types). Information hiding is a process to build objects.

To Top