Object Oriented Progrmming : Object Oriented Programming Basic(OOPs Basic):, Access Specifiers, C++ Objects, Abstraction, Ecapsulation, Inheritance.



Object oriented programming works on object instead of functions.
An object is a real world entity.
For Example:
Cat , Car , Ball, Chair, Bench, Blackboard are some of the examples of real world objects
An object represents two things
a) State – Dog has 4 legs , 1 tail , 2 ears . It shows the dog state
b) Behavior- are the functions or methods , that uses the state and shows behavior of an object.
For example : dog jumps, so for this it is depend on legs.


classes are the central feature of object-oriented programming and are often called user-defined types.
A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.
Classes are also known as a collection of similar objects or objects of same type.
A template that describes the kinds of state and behavior that objects of its type support.
The data and functions within a class are called members of the class.
 The variables declared inside a class are known as "Data Members" and the functions are known as "Member Functions".

class class-name
access specifier:
data and functions
In the above syntax the every class has a unique name, the "access specifier" can either private, public, protected.
All the elements of a class are private by default.

class Box
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private  or protected which we will discuss in a sub-section.


Defines the access rights for the statements or functions that follows it until another access specifier or till the end of a class. The three types of access specifiers are "private", "public", "protected".
Private: The members declared as "private" can be accessed only within the same class and not from outside the class.
Public: The members declared as "public" are accessible within the class as well as from outside the class.
Protected: The members declared as "protected" cannot be accessed from outside the class, but can be accessed from a derived class. This is used when inheritance is applied to the members of a class.


A class provides the blueprints for objects, so basically an object is created from a class.
Objects are instance of a class, that interact with each other at runtime.
In terms of variables, a class would be the type, and an object would be the variable.
We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types.
Following statements declare two objects of class Box:
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box


Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.
Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation.
Let's take one real life example of a TV, which you can turn on and off, change the channel, adjust the volume, and add external components such as speakers, VCRs, and DVD players, But you do not know its internal details, that is, you do not know how it receives signals over the air or through a cable, how it translates them, and finally displays them on the screen.


The wrapping up of data and function into a single unit (called class) is known as encapsulation.
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse.
Data encapsulation led to the important OOP concept of data hiding. AS the data is not accessible to the outside world, and only those functions which are wrapped in the class can access it.


Inheritance is the process by which objects of one class acquired the properties of objects of another classes.
Inheritance is a method by which new classes are created or derived from the existing classes.
Inheritance allows us to define a class in terms of another class.
This also provides an opportunity to reuse the code functionality and fast implementation time.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
Using Inheritance some qualities of the base classes are added to the newly derived class, apart from its own features

Syntax of inheritance

class derived-class: access-specifier base-class;
Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined class. If the access - specifier is not used, then it is private by default.
class Rectangle : public Shape;
class Rectangle : private Shape;
class Rectangle : protected Shape;

Inheritance types

Following are the different types of inheritance followed in C++.
Single Inheritance
Multiple Inheritance
Hierarchical Inheritance
Multilevel Inheritance
Hybrid Inheritance

Single Inheritance

Single Inheritance is a method in which a derived class has only one base class.

Multiple inheritance

Multiple Inheritance is a method by which a class is derived from more than one base class.

Hierarchical Inheritance

Hierarchical Inheritance is a method of inheritance where one or more derived classes is derived from common base class.

Multilevel Inheritance

Multilevel Inheritance is a method where a derived class is derived from another derived classMultilevel Inheritance is a method where a derived class is derived from another derived class.