|
Answer» There are four major concepts in Object-Oriented Programming. They are as follows: - Encapsulation: Encapsulation is described as the binding of data and the functions that alter it in Object-Oriented Programming. Encapsulation makes a class's variables or data concealed from other classes and that they can only be accessible through member functions of the class in which it is stated.
Let us consider the following example: In a company, there are different divisions such as accounts, finance, sales, and so on. The finance department’s duty is to keep track of all financial data and the transactions performed on them. Similarly, the sales department’s duty is to keep track of all sales-related activities. Let us assume that an official from the finance department requires the sales data for a specific month. In this scenario, he cannot access the sales section's data directly. An official from the sales department must be contacted because only he can access the data. Here, the process of asking the sales officials for the data depicts encapsulation. The sales department's data and the people who can influence it are BUNDLED together under the category "sales section." - Abstraction: Abstraction refers to revealing only the most important information while concealing the details. Data abstraction refers to exposing only the most important aspects of the data to the outside world while concealing the implementation specifics.
Consider the case of a man driving a vehicle. The man only knows that pressing the accelerators will increase the vehicle's speed and that applying the brakes will STOP it, but he has no idea how the speed is increased by pressing the accelerators, nor does he understand the car's inner mechanism or how the accelerator, brakes, and other controls are implemented in the car. This is the definition of abstraction. - Inheritance: Inheritance refers to a class's capacity to derive features and traits from another class. One of the most significant characteristics of Object-Oriented Programming is inheritance. A class that inherits properties from another class is referred to as a subclass or a DERIVED class. A class whose properties and member functions are inherited by other classes are referred to as superclass or base class. Inheritance SUPPORTS the concept of "reusability".
Consider a class Vehicle that contains all the essential functions which a vehicle must possess. This includes accelerating speed, applying brakes, changing gear and so on. Now let us assume the classes Car, Bus, Truck and so on. All of these classes can be considered as a subclass of the class Vehicle since all of them must essentially possess all the properties of the class Vehicle. - Polymorphism: Polymorphism refers to the fact that something exists in multiple forms. Polymorphism, in simple terms, is the ability of a message to be displayed in multiple formats. For example, at the same time, a person might have a variety of characteristics. At the same time, he is a father, a spouse, and a worker. As a result, the same person behaves differently in different settings. Polymorphism is the term for this.
There are mainly two types of polymorphism in C++. They are as follows:- Compile Time Polymorphism: Function overloading and operator overloading is USED to achieve this form of polymorphism.
- Runtime Polymorphism: Function Overriding is used to generate this form of polymorphism.
|