1.

Explain in detail about data encapsulation and inheritance.

Answer»

1. Encapsulation:
It is the method of combining the data and functions within a class. This hides the data from being accessed from outside a class directly and only through the functions inside the class one is able to access the information.

This is also known as “Data Abstraction”, as it gives a clear separation between properties of data type and the associated implementation details. There are two types, known as “function abstraction” and “data abstraction”. A Function when used without knowing how implemented function abstraction. Data abstraction is using data without knowing how the data is stored.

2. Inheritance:
Inheritance is the process of creating a new class, called derived class, from an existing or base classes. The derived class inherits all the capabilities of the base class but in addition, can have its own capability. Inheritance permits code reusability. Once a base class is written and debugged, it need not be touched. Reusing existing code saves time and money and increases a program’s reliability.

Inheritance can also help in the original conceptualization of a programming problem, and in the overall design of the program. A programmer can use a class created by another person or company, and without modifying it, derive at other classes which are suited to particular situations.



Discussion

No Comment Found