0% found this document useful (0 votes)
12 views14 pages

OOPS Concept

The document discusses object-oriented programming concepts in C++ including classes, objects, class methods, constructors, destructors, access specifiers, inheritance, polymorphism, and more.

Uploaded by

Deepak Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

OOPS Concept

The document discusses object-oriented programming concepts in C++ including classes, objects, class methods, constructors, destructors, access specifiers, inheritance, polymorphism, and more.

Uploaded by

Deepak Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

OOPS concept

CLASS AND OBJECT


 Class is a template for object
 Object is a instance of class

CLASS METHODS
 Function inside the class
 Function definition outside the class
 Passing parameter to the function

CONSTRUCTOR
special method that is automatically called when an object of a class is created.

Constructor parameters

Constructor definition outside the class


Copy constructor
A copy constructor in C++ is a special constructor that initializes an object using another
object of the same class. It's used to create a new object as a copy of an existing object.

STATIC KEYWORD
static variable inside a class is shared among all instances of that class
Static data member and static member function

DESTRUCTOR
 A destructor in C++ is a special member function of a class that is called
automatically when an object of that class is destroyed.
 It is used to clean up resources allocated by the object before it is removed from
memory.
 Destructors have the same name as the class preceded by a tilde (~).

ACCESS SPECIFIERS
 Public - accessible from outside the class
 Private - cannot be accessed (or viewed) from outside the class
 Protected - cannot be accessed from outside the class, however, they can be accessed
in inherited classes.
By default, all members of a class are private if you don't specify an access specifier:
FRIEND CLASS FUNCTION

ENCAPSULATION
INHERITANCE

SINGLE INHERITANCE

Passing value to constructor when inherited


MULTILEVEL INHERITANCE

MULTIPLE INHERITANCE
HIERARCHICAL INHERITANCE
HYBRID INHERITANCE
Hybrid inheritance is a combination of more than one type of inheritance.
POLYMORPHISM

COMPILE TIME
This type of polymorphism is achieved by function overloading or operator overloading.
Function Overloading
multiple functions with the same name.
Operator Overloading

Operator that cannot be overloaded


o Scope operator (::)
o Sizeof
o member selector(.)
o member pointer selector(*)
o ternary operator(?:)

RUN TIME
Function overriding
If derived class defines same function as defined in its base class, it is known as function
overriding in C++.
Virtual Function

The above same program when used virtual keyword


Pure Virtual function
o A virtual function is not used for performing any task. It only serves as a
placeholder.
o When the function has no definition, such function is known as "do-nothing"
function.
o The "do-nothing" function is known as a pure virtual function. A pure virtual
function is a function declared in the base class that has no definition relative
to the base class.

You might also like