Chapter Regression PDF
Chapter Regression PDF
In the upcoming sections, let’s see each object-oriented programming feature in detail.
Classes and Objects in OOPs
A class is a template that consists of the data members or variables and functions and defines
the properties and methods for a group of objects.
The compiler does not allocate memory whenever you define a class.
Example:
You can define a class called Vehicle. Its data fields can be vehicle_name, model_number,
color, date_of_manufacture, etc.
An object is nothing but an instance of a class. Each object has its values for the
different properties present in its class. The compiler allocates memory for each object.
Example:
The different objects of the class Vehicle can be Car, Bike, Bicycle, etc. Each of them will
have its values for the fields like color, model_number, etc.
Abstraction
The literal meaning of abstraction is to remove some characteristics from something to
reduce it to a smaller set. Similarly, Object Oriented Programming abstraction exposes only
the essential information of an object to the user and hides the other details.
In real life, like when you toggle a switch, it simply turns on or off the lights. Here, we only
know the functionality of the switch, but we don’t know its internal implementation, like how
it works.
How to implement abstraction?
You can implement abstraction using classes that group the data members and function
together. Inside classes, you can choose the access specifiers for its members to control how
they are visible to the outside world. We can also create header files containing the
implementations of all the necessary functions. So, you can include the header file and call
these functions without getting into their implementation.
Advantages of Abstraction
The advantages of abstraction are as follows:
It enables code reuse by avoiding code duplication.
It enhances software security by making only necessary information available to the users
and hiding the complex ones.
Inheritance
Inheritance is one of the most important features of object oriented programming. It allows a
class to inherit the properties and methods of another class called the parent class, the base
class, or the super-class.
The class that inherits is called the child class or sub-class.
It helps to avoid duplication of codes by allowing code reuse as you need not define the same
methods and properties present in a super-class in the sub-classes again. The sub-class can
simply inherit them.
Example:
You can have a parent class called “Shape” and other classes like Square, Circle, Rectangle,
etc. Since all these are also shapes, they will have all the properties of a shape so that they
can inherit the class Shape.
Polymorphism
The word polymorphism means to have many forms. So, by using polymorphism, you can
add different meanings to a single component.
There are two types of polymorphism:
Run-time polymorphism
Compile-time polymorphism
Example:
You can have some private variables in a class that you can't access outside the class for
security reasons. Now, to read or change the value of this variable, you can define public
functions in the class which will perform the read or writes operations.
Know What is Object in OOPs here in detail.
Other Oops Features:
Dynamic Binding
Dynamic binding takes place during run time based on the type of object. Since it is delayed
till the run time, it is also called late binding or runtime binding. When the compiler cannot
determine all the information required to resolve a function call during compile time, these
function calls are not bound until run time.
Message Passing
Message passing refers to the process of passing a message, or data, between different objects
or components in a program. This can be done in many ways, such as function calls, events,
or inter-process communication. The specific implementation of message passing will depend
on the program's design and the system's needs.