You are on page 1of 20

 C++ OOPS CONCEPT

Introduction to C++ OOPs Concept: -


 The major purpose of C++ programming is to introduce the concept of
object orientation to the C programming language.
 Object oriented programming provide many concept such as inheritance,
data binding, polymorphism etc.
 The programming where everything is represented as an object is known
as object oriented programming language.

 Smalltalk is first considered as truly object oriented programming


language.
 TYPES OF OOPS
CONCEPTS
 Class
 Object
 Inheritance
 Polymorphism
Abstraction
Encapsulation
 CLASS

1. A class is user defined data type which holds both data and function to operate on
them the data of the class is called Data member. And the function of the class
are called Member function.
2. These member can be private and public. By default all members of a class are
private.
3. We can specify the member as public. The private member of the class cannot be
accessed outside the class.
4. Class is like a blue print for an object.
 OBJECT

1. Object means the variable of the class type.


2. Any entity that has a state and behavior is known as an object.
3. For ex: - chair, pen, table, etc. these object can be physical and
logical.
 INHERITANCE
1. When one object acquires all the properties & behavior of parent object i.e.
known as inheritance.
2. It provide code reusability.
3. It is used to achieve of runtime polymorphism.
 POLYMORPHISM
1. When one task performed by different ways i.e. is known as polymorphism.
2. For ex: - to convince the customer differently.
3. In C++, we use function overloading and function overriding to achieve
polymorphism.
 ABSTRACTION

1. Hiding details and showing functionality is known as


abstraction.
2. For ex: - phone call, we don’t know the internal processing.
3. In C++, we use abstract class and interface to achieve
abstraction.
 ENCAPSULATION
1. Binding (or wrapping) code and data together into a single unit is
called encapsulation.
2. For example: - capsule, it is wrapped with different medicines.
 INHERITANCE

Introduction to inheritance: -
1. The capability of a class to derive the properties and charters tics from another class is
inheritance.
2. Inheritance is one of the most important feature of OOPs that allow the child class to acquire
the properties (data members) and functionalities (member function) of parent class.
3. Child class: - a class that inherits another class is know as child class, sub class & derived
class.
4. Parent class: - the class that is being inherited by other class is known as parent class, super
class & base class.
 TYPES OF
INHERITANCE
Single inheritance
Multilevel inheritance
Hierarchal inheritance
Multiple inheritance
Hybrid inheritance
 SINGLE INHERITANCE
1. In this type of inheritance there is
only one parent class and one child
class.
2. The child class inherits the
properties and characteristics of the
parent class.
 MULTILEVEL
INHERITANCE
In this type of inheritance class A is
inherited by class B and class C inherits
the class B that is why this is called
multilevel inheritance.
 HIERARCHICAL INHERITANCE
1. In this type of inheritance there is only one parent class and two or three child
class.
2. These classes inherits properties of the parent class. So this inheritance is also
called hierarchical inheritance.
MULTIPLE INHERITANCE
1. In this type of inheritance there is only one child class and two
or three parent class.
2. That single child class inherits the properties of three parent
class . i.e. this is also known as multiple inheritance.
HYBRID INHERITANCE
This type of inheritance is a combination of two types
of inheritance, that is why this is also called hybrid
inheritance. But there is an anomaly, which is that class
B and class C both inherits the class A which is parent
class, so both class have same copy of their parent class
which is class A. So that system gets confused by
getting two copies of class A by class B and class C and
both of these classes are inherited by class D there is
way to remove this anomaly, which is- define classes as
virtual class so that both class, B and C have virtual
copies of class A so system doesn’t get confused for
class A. This inheritance is also known for making
diamond structure.
POLYMORPHISM

What do you understand by polymorphism: -


Polymorphism is one of the most important features of (OOPs). It is
derived from two Latin words which are ‘poly’ means ‘many’ and
‘morphism’ means ‘form’.
 IT IS IMPLEMENTED BY
USING THE CONCEPT OF: -
Function overloading
Operator overloading
Function overriding
FUNCTION OVERLOADING
Function overloading provides a way to have multiple function with the same name
but they differ in return type, number of argument and type of argument . We use
the following example to define function overloading.
OPERATOR OVERLOADING
1. Most build in data type have
predefined associated with them.
2. For ex: - the int data type of C++
along with the operators +,-
,*,/,++,--.
3. An operator can be overloaded by
defining a function for it the
function for the operator is define
by using the operator keyword.
4. Only a predefined set of C++
operators can be overloaded.
FUNCTION OVERRIDING
In a class hierarchal where function is derived
class having the same name and same type as a
function in a base class then the function in the
derived class overwrite a function in the base
class.
When you & overwritten function from a
derived class it always refers to the function
define by the derived class the version of the
function define by the base class will be
hidden.

You might also like