|
Answer» The following are the 4 major pillars of Object-Oriented Programming: - Abstraction - Abstraction is a technique for displaying only the information that is required while hiding the rest. Abstraction is the process of picking data from a huge set of data in order to display the information required, hence minimizing programming complexity and effort. Let us consider an example to understand it better. A car driver knows best how to drive a car. He knows when he should apply brakes when he should accelerate. However, he might not be aware of how the entire car works. He does not need to know the working of these functionalities in order to drive a car. This can be considered as a real-life example of abstraction since the driver is unaware of the complex details and is only concerned with how to operate the functionality.
- ENCAPSULATION - Encapsulation can be described as the grouping of information into a single unit. It's the glue that holds code and the data it manipulates together. Encapsulation can also be thought of as a protective shield that prevents data from being accessible by code outside of the shield.
Encapsulation MEANS that a class's variables or data are concealed from other classes and can only be ACCESSED through the member functions of the class in which they are specified. Data-hiding is similar to encapsulation in that the data in a class is concealed from other classes. - Inheritance - Inheritance is a crucial component of OOP (Object Oriented Programming). It is a Java mechanism that allows one class to inherit the characteristics (FIELDS and METHODS) of another.
- Superclass: A superclass is a class whose characteristics are inherited (or a base class or a parent class).
- Subclass: A subclass is a class that inherits from another class (or a derived class, extended class, or child class). In addition to the superclass fields and methods, the subclass can add its own fields and methods.
Inheritance supports the concept of "reusability," which means that if we want to create a new class but there is already one that contains some of the code we need, we can derive our new class from the old one. We're reusing the old class's fields and functions in this way.
- Polymorphism - Polymorphism is an OOP concept that describes a variable, object, or function's ability to take on various forms. In English, the verb run, for example, has distinct meanings depending on whether it is used with a laptop, a foot race, or a corporation. We can deduce the meaning of run from the other words used in the sentence. Polymorphism can be treated in the same way.
|