What is OOPs ?
OOP stands for Object-Oriented Programming.
It organizes code using objects, bundling data and methods together. Encapsulation protects data, inheritance promotes code reuse, and polymorphism allows the use of a common interface for different object types. It enhances code structure and flexibility in software development.
Advantage of OOPs ?
- OOPs programming paradigm is considered as a better style of programming.
- OOP is faster and easier to execute.
- It allows us the reusability of code.
- OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug.
- Reduce the complexity.
What are Classes and Objects?
Class : A class is a blue print that define the variable and the methods common to all entities of a certain kind , collection of objects is called class , it's a logical entity.
Objects : Objects is a real world entity that has state and behaviour , state - data store in variable , behaviour - functionality define in method . for example - a chair , pen , table , it can be physical or logical.
So, a class is a template for objects, and an object is an instance of a class.
When the individual objects are created, they inherit all the variables and functions from the class.
When the individual objects are created, they inherit all the variables and functions from the class.
Different between class and object ?
- Class is used as a template for declaring and creating the object. an object is a variable of a class .
- A class is a logical entity , an object is a physical or logical entity .
- When class is created no memory is allocated . object are allocated memory space whenever they are created .
- A class can not be manipulated as they are not available in the memory . object can be manipulate.
- The class has to be declared only once , an object is created many times as per requirement .
CONSTRUCTOR : A constructor is a special method of a class which is automatically executed when an
object of a class is created ,its name is same as class name ,it's has no return type . it is used to initialized the object .
Even if we don't define any constructor ,then the compiler will automatically provide a default constructor, constructor should be define in a public section .
Parameterized Constructors : The constructor having a specific number of parameter to be passed .
Default Constructor : When it does not have any parameter .
Overloading Constructors : multiple constructors have the same name as long as the number or type of
parameter are different .
A class can have multiple constructors but the number and type of parameter must be different .
DESTRUCTOR : is a special method of a class which deletes an object and free up memory , the
destructor neither takes any parameters not returns any value .
Access Specifiers :
Private access specifiers : Member can not be accessible outside the class .
Public access specifiers : Member are accessible outside the class .
Protected access specifiers : Member are only accessible in the inherited class .
ENCAPSULATION :
Refers to wrapping up of similar data and functionalities into a single unit .
The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users. To achieve this, you must declare class variables/attributes as
private (cannot be accessed from outside the class). If you want others to read or modify the value of a private member, you can provide public get and set methods.INHERITANCE :
The capability of class to inherit attributes and methods from one class to another is
called inheritance . inheritance to reduce code redundancy by creating a superclass person .
We group the "inheritance concept" into two categories -
- The class that inherits properties from another class is called child class or derived class or sub class .
- The class whose properties are inherited by a child class is called parent class or base class or super class .
Advantages of Inheritance :
- Reduce code redundancy.
- increases code reusability.
- Save time and effort as the main code present in the super class, not need to written again.
Type of Inheritance :
Single : One super class one sub class
Multilevel : A class can also be derived from one class which is already derived from Another class.
Multiple : Multiple super class and single sub class.
Hierarchical : Single super class and multiple sub class
Hybrid : Combining various type of inheritance like multiple , simple and hierarchical inheritance is
known as hybrid inheritance.
POLYMORPHISM :
Polymorphism means "many forms", is a feature of oops that allows the object to behave
differently in different conditions . a women is a responsible mother , employee , and customer .
Type of Polymorphism :
- Compile time ( function overloading ) .
- Runtime ( function overriding ,virtual function ) .
function overloading : multiple function can have the same name as long as the number and type of
parameter are different .
function overriding is a feature of oops that allow us to override
a function of parent class in child class , its a example of runtime polymorphism .
ABSTRACTION :
refers to hiding the implementation details of a particular functionalities .
0 Comments