SlideShare a Scribd company logo
1 of 17
Friend Functions
• A friend function of a class is defined outside that class' scope but it has the right to
access all private and protected members of the class.
• Even though the prototypes for friend functions appear in the class definition,
friends are not member functions.
• A friend can be a function, function template, or member function, or a class or
class template, in which case the entire class and all of its members are friends.
Example
class Box
{
double width;
public:
double length;
friend void printWidth( Box box );
void setWidth( double wid );
};
Inline Functions
• C++ inline function is powerful concept that is commonly used with classes.
• If a function is inline, the compiler places a copy of the code of that function at
each point where the function is called at compile time.
• To inline a function, place the keyword inline before the function name and define
the function before any calls are made to the function. The compiler can ignore the
inline qualifier in case defined function is more than a line.
• A function definition in a class definition is an inline function definition, even
without the use of the inline specifier.
• For Example
inline int Max(int x, int y)
{ return (x > y)? x : y;}
This Pointer
• Every object in C++ has access to its own address through an important pointer
called this pointer.
• The this pointer is an implicit parameter to all member functions.
• Therefore, inside a member function, this may be used to refer to the invoking
object.
• Friend functions do not have a this pointer, because friends are not members of a
class. Only member functions have a this pointer.
• The ‘this’ pointer is passed as a hidden argument to all non-static member function
calls and is available as a local variable within the body of all nonstatic functions.
• The ‘this’ pointer is a constant pointer that holds the memory address of the current
object.
• The ‘this’ pointer is not available in static member functions as static member
functions can be called without any object (with class name).
• ‘this’ pointer is used when local variable’s name is same as member’s name
This Pointer (Cont..)
#include<iostream>
#include<conio.h>
using namespace std;
class Test
{
private:
int x;
public:
void setX (int x)
{
this->x = x;
}
void print()
{ cout << "x = " << x << endl; }
};
Static Members
• We can define class members static using static keyword.
• When we declare a member of a class as static it means no matter how many
objects of the class are created, there is only one copy of the static member.
• A static member is shared by all objects of the class. All static data is initialized to
zero when the first object is created, if no other initialization is present
• By declaring a function member as static, you make it independent of any
particular object of the class.
• A static member function can be called even if no objects of the class exist and
the static functions are accessed using only the class name and the scope
resolution operator ::.
• static member function can only access static data member, other static
member functions and any other functions from outside the class.
Inheritance
• The capability of a class to derive properties and characteristics from another class
is called Inheritance.
• Inheritance is one of the most important feature of Object Oriented Programming.
• Sub Class: The class that inherits properties from another class is called Sub class
or Derived Class.
• Super Class: The class whose properties are inherited by sub class is called Base
Class or Super class.
• This existing class is called the base class, and the new class is referred to as the
derived class.
• The base class is also called parent class and derived class is also called child
class.
Inheritance – “IS A” or
“IS A KIND OF” Relationship
Inheritance – Advantages
► Reuse
► Less redundancy
► Increased maintainability
Main purpose of inheritance is reuseWe can easily add new classes by
inheriting from existing classes
– Select an existing class closer to the desired functionality
– Create a new class and inherit it from the selected class
– Add to and/or modify the inherited functionality
• Syntax:
class subclass_name : access_mode base_class_name
{ //body of subclass };
Modes of Inheritance
Public mode:
• If we derive a sub class from a public base class.
• Then the public member of the base class will become public in the derived class
and protected members of the base class will become protected in derived class.
Protected mode:
• If we derive a sub class from a Protected base class.
• Then both public member and protected members of the base class will become
protected in derived class.
Private mode:
• If we derive a sub class from a Private base class.
• Then both public member and protected members of the base class will become
Private in derived class.
Inheritance Types
Single Inheirtance:
• In single inheritance, a class is allowed to inherit from only one class. i.e. one sub
class is inherited by one base class only.
Multiple Inheritance:
• Multiple Inheritance is a feature of C++ where a class can inherit from more than
one classes. i.e one sub class is inherited from more than one base classes.
Multilevel Inheritance:
• In multilevel inheritance, a derived class is created from another derived class.
Hierarchical inheritance
• In Hierarchical inheritance, more than one sub class is inherited from a single base
class.
Hybrid Inheritance
• Hybrid Inheritance is implemented by combining more than one type of
inheritance.
• For example: Combining Hierarchical inheritance and Multiple Inheritance.
Polymorphism
• The word polymorphism means having many forms.
• In OOP, Polymorphism means that a call to a member function will cause a
different function to be executed depending on the type of object that invokes the
function.
• Polymorphism is a feature of OOP that allows the object to behave differently in
different conditions.
In OOP we have two types of polymorphism:
• Compile time Polymorphism – This is also known as static (or early) binding.
• Runtime Polymorphism – This is also known as dynamic (or late) binding.
Compile time Polymorphism
• Function overloading and Operator overloading are perfect example of Compile
time polymorphism.
Compile time Polymorphism Example
• In this example, we have two functions with same name but different number of
arguments.
Polymorphism
Runtime Polymorphism
Function overriding is an example of Runtime polymorphism.
Function Overriding:
• When child class declares a method, which is already present in the parent class
then this is called function overriding, here child class overrides the parent class.
• In case of function overriding we have two definitions of the same function, one is
parent class and one in child class.
• The call to the function is determined at runtime to decide which definition of the
function is to be called, that's the reason it is called runtime polymorphism.
Function overloading
• Function overloading is a C++ programming feature that allows us to have more
than one function having same name but different parameter list.
• When I say parameter list, it means the data type and sequence of the parameters.
– different type
– number sequence of parameters
Polymorphism
Advantages of Function overloading
• The main advantage of function overloading is to the improve the code
readability and allows code reusability.
• In the example 1, we have seen how we were able to have more than one function
for the same task(addition) with different parameters.
• This allowed us to add two integer numbers as well as three integer numbers.
Function Overriding in C++
• Function overriding is a feature that allows us to have a same function in child class
which is already present in the parent class.
• A child class inherits the data members and member functions of parent class, but
when you want to override functionality in the child class then you can use function
overriding.
• It is like creating a new version of an old function, in the child class.
Polymorphism
Function Overriding Example
• To override a function you must have the same signature in child class.
• By signature I mean the data type and sequence of parameters.
• Here we don’t have any parameter in the parent function so we didn’t use any
parameter in the child function.
Difference between Function Overloading and Function overriding in C++
• Function Overloading happens in the same class when we declare same functions
with different arguments in the same class. Function Overriding is happens in the
child class when child class overrides parent class function.
• In function overloading function signature should be different for all the overloaded
functions. In function overriding the signature of both the functions (overriding
function and overridden function) should be same.
• Overloading happens at the compile time thats why it is also known as compile
time polymorphism while overriding happens at run time which is why it is known
as run time polymorphism.
Polymorphism
Virtual functions in C++: Runtime Polymorphism
• When we declare a function as virtual in a class, all the sub classes that override
this function have their function implementation as virtual by default (whether they
mark them virtual or not).
Why we declare a function virtual?
• To let compiler know that the call to this function needs to be resolved at runtime
(also known as late binding and dynamic linking) so that the object type is
determined and the correct version of the function is called.
Data Encapsulation
All C++ programs are composed of the following two fundamental elements:
– Program statements (code): This is the part of a program that performs
actions and they are called functions.
– Program data: The data is the information of the program which affected by
the program functions.
• 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.
• Data encapsulation is a mechanism of bundling the data, and the functions that use
them.
• Data abstraction is a mechanism of exposing only the interfaces and hiding the
implementation details from the user.
Data Encapsulation
• C++ supports the properties of encapsulation and data hiding through the creation
of user-defined types, called classes.
• We already have studied that a class can contain private, protected and public
members.
• By default, all items defined in a class are private.
• Making one class a friend of another exposes the implementation details and
reduces encapsulation.
• The ideal is to keep as many of the details of each class hidden from all other
classes as possible.
Data Abstraction
• 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.
• Thus, we can say a television clearly separates its internal implementation from its
external interface and you can play with its interfaces like the power button,
channel changer, and volume control without having zero knowledge of its
internals.

More Related Content

Similar to full defination of final opp.pptx

Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptxSAICHARANREDDYN
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and PolymorphismKartikKapgate
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentalsAnsgarMary
 
OOPS – General Understanding in .NET
OOPS – General Understanding in .NETOOPS – General Understanding in .NET
OOPS – General Understanding in .NETSabith Byari
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritancemcollison
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEVinishA23
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.pptAshwathGupta
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with javaAAKANKSHA JAIN
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsRaja Sekhar
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptxAtharvPotdar2
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 

Similar to full defination of final opp.pptx (20)

Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Oops
OopsOops
Oops
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Virtual Function
Virtual FunctionVirtual Function
Virtual Function
 
OOPS – General Understanding in .NET
OOPS – General Understanding in .NETOOPS – General Understanding in .NET
OOPS – General Understanding in .NET
 
Oopsinphp
OopsinphpOopsinphp
Oopsinphp
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
29c
29c29c
29c
 
29csharp
29csharp29csharp
29csharp
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
 
C++ first s lide
C++ first s lideC++ first s lide
C++ first s lide
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 

Recently uploaded

Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...lizamodels9
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensorsonawaneprad
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsHajira Mahmood
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |aasikanpl
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxFarihaAbdulRasheed
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.PraveenaKalaiselvan1
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024AyushiRastogi48
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxmalonesandreagweneth
 
Transposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptTransposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptArshadWarsi13
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPirithiRaju
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptx
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptxBREEDING FOR RESISTANCE TO BIOTIC STRESS.pptx
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptxPABOLU TEJASREE
 
FREE NURSING BUNDLE FOR NURSES.PDF by na
FREE NURSING BUNDLE FOR NURSES.PDF by naFREE NURSING BUNDLE FOR NURSES.PDF by na
FREE NURSING BUNDLE FOR NURSES.PDF by naJASISJULIANOELYNV
 
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfBUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfWildaNurAmalia2
 

Recently uploaded (20)

Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
 
Environmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial BiosensorEnvironmental Biotechnology Topic:- Microbial Biosensor
Environmental Biotechnology Topic:- Microbial Biosensor
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutions
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
 
Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024Vision and reflection on Mining Software Repositories research in 2024
Vision and reflection on Mining Software Repositories research in 2024
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
 
Transposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptTransposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.ppt
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdfPests of soyabean_Binomics_IdentificationDr.UPR.pdf
Pests of soyabean_Binomics_IdentificationDr.UPR.pdf
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptx
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptxBREEDING FOR RESISTANCE TO BIOTIC STRESS.pptx
BREEDING FOR RESISTANCE TO BIOTIC STRESS.pptx
 
FREE NURSING BUNDLE FOR NURSES.PDF by na
FREE NURSING BUNDLE FOR NURSES.PDF by naFREE NURSING BUNDLE FOR NURSES.PDF by na
FREE NURSING BUNDLE FOR NURSES.PDF by na
 
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdfBUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
BUMI DAN ANTARIKSA PROJEK IPAS SMK KELAS X.pdf
 

full defination of final opp.pptx

  • 1. Friend Functions • A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. • Even though the prototypes for friend functions appear in the class definition, friends are not member functions. • A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends. Example class Box { double width; public: double length; friend void printWidth( Box box ); void setWidth( double wid ); };
  • 2. Inline Functions • C++ inline function is powerful concept that is commonly used with classes. • If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time. • To inline a function, place the keyword inline before the function name and define the function before any calls are made to the function. The compiler can ignore the inline qualifier in case defined function is more than a line. • A function definition in a class definition is an inline function definition, even without the use of the inline specifier. • For Example inline int Max(int x, int y) { return (x > y)? x : y;}
  • 3. This Pointer • Every object in C++ has access to its own address through an important pointer called this pointer. • The this pointer is an implicit parameter to all member functions. • Therefore, inside a member function, this may be used to refer to the invoking object. • Friend functions do not have a this pointer, because friends are not members of a class. Only member functions have a this pointer. • The ‘this’ pointer is passed as a hidden argument to all non-static member function calls and is available as a local variable within the body of all nonstatic functions. • The ‘this’ pointer is a constant pointer that holds the memory address of the current object. • The ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name). • ‘this’ pointer is used when local variable’s name is same as member’s name
  • 4. This Pointer (Cont..) #include<iostream> #include<conio.h> using namespace std; class Test { private: int x; public: void setX (int x) { this->x = x; } void print() { cout << "x = " << x << endl; } };
  • 5. Static Members • We can define class members static using static keyword. • When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member. • A static member is shared by all objects of the class. All static data is initialized to zero when the first object is created, if no other initialization is present • By declaring a function member as static, you make it independent of any particular object of the class. • A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::. • static member function can only access static data member, other static member functions and any other functions from outside the class.
  • 6. Inheritance • The capability of a class to derive properties and characteristics from another class is called Inheritance. • Inheritance is one of the most important feature of Object Oriented Programming. • Sub Class: The class that inherits properties from another class is called Sub class or Derived Class. • Super Class: The class whose properties are inherited by sub class is called Base Class or Super class. • This existing class is called the base class, and the new class is referred to as the derived class. • The base class is also called parent class and derived class is also called child class. Inheritance – “IS A” or “IS A KIND OF” Relationship
  • 7. Inheritance – Advantages ► Reuse ► Less redundancy ► Increased maintainability Main purpose of inheritance is reuseWe can easily add new classes by inheriting from existing classes – Select an existing class closer to the desired functionality – Create a new class and inherit it from the selected class – Add to and/or modify the inherited functionality • Syntax: class subclass_name : access_mode base_class_name { //body of subclass };
  • 8. Modes of Inheritance Public mode: • If we derive a sub class from a public base class. • Then the public member of the base class will become public in the derived class and protected members of the base class will become protected in derived class. Protected mode: • If we derive a sub class from a Protected base class. • Then both public member and protected members of the base class will become protected in derived class. Private mode: • If we derive a sub class from a Private base class. • Then both public member and protected members of the base class will become Private in derived class.
  • 9. Inheritance Types Single Inheirtance: • In single inheritance, a class is allowed to inherit from only one class. i.e. one sub class is inherited by one base class only. Multiple Inheritance: • Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. i.e one sub class is inherited from more than one base classes. Multilevel Inheritance: • In multilevel inheritance, a derived class is created from another derived class. Hierarchical inheritance • In Hierarchical inheritance, more than one sub class is inherited from a single base class. Hybrid Inheritance • Hybrid Inheritance is implemented by combining more than one type of inheritance. • For example: Combining Hierarchical inheritance and Multiple Inheritance.
  • 10. Polymorphism • The word polymorphism means having many forms. • In OOP, Polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. • Polymorphism is a feature of OOP that allows the object to behave differently in different conditions. In OOP we have two types of polymorphism: • Compile time Polymorphism – This is also known as static (or early) binding. • Runtime Polymorphism – This is also known as dynamic (or late) binding. Compile time Polymorphism • Function overloading and Operator overloading are perfect example of Compile time polymorphism. Compile time Polymorphism Example • In this example, we have two functions with same name but different number of arguments.
  • 11. Polymorphism Runtime Polymorphism Function overriding is an example of Runtime polymorphism. Function Overriding: • When child class declares a method, which is already present in the parent class then this is called function overriding, here child class overrides the parent class. • In case of function overriding we have two definitions of the same function, one is parent class and one in child class. • The call to the function is determined at runtime to decide which definition of the function is to be called, that's the reason it is called runtime polymorphism. Function overloading • Function overloading is a C++ programming feature that allows us to have more than one function having same name but different parameter list. • When I say parameter list, it means the data type and sequence of the parameters. – different type – number sequence of parameters
  • 12. Polymorphism Advantages of Function overloading • The main advantage of function overloading is to the improve the code readability and allows code reusability. • In the example 1, we have seen how we were able to have more than one function for the same task(addition) with different parameters. • This allowed us to add two integer numbers as well as three integer numbers. Function Overriding in C++ • Function overriding is a feature that allows us to have a same function in child class which is already present in the parent class. • A child class inherits the data members and member functions of parent class, but when you want to override functionality in the child class then you can use function overriding. • It is like creating a new version of an old function, in the child class.
  • 13. Polymorphism Function Overriding Example • To override a function you must have the same signature in child class. • By signature I mean the data type and sequence of parameters. • Here we don’t have any parameter in the parent function so we didn’t use any parameter in the child function. Difference between Function Overloading and Function overriding in C++ • Function Overloading happens in the same class when we declare same functions with different arguments in the same class. Function Overriding is happens in the child class when child class overrides parent class function. • In function overloading function signature should be different for all the overloaded functions. In function overriding the signature of both the functions (overriding function and overridden function) should be same. • Overloading happens at the compile time thats why it is also known as compile time polymorphism while overriding happens at run time which is why it is known as run time polymorphism.
  • 14. Polymorphism Virtual functions in C++: Runtime Polymorphism • When we declare a function as virtual in a class, all the sub classes that override this function have their function implementation as virtual by default (whether they mark them virtual or not). Why we declare a function virtual? • To let compiler know that the call to this function needs to be resolved at runtime (also known as late binding and dynamic linking) so that the object type is determined and the correct version of the function is called.
  • 15. Data Encapsulation All C++ programs are composed of the following two fundamental elements: – Program statements (code): This is the part of a program that performs actions and they are called functions. – Program data: The data is the information of the program which affected by the program functions. • 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. • Data encapsulation is a mechanism of bundling the data, and the functions that use them. • Data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user.
  • 16. Data Encapsulation • C++ supports the properties of encapsulation and data hiding through the creation of user-defined types, called classes. • We already have studied that a class can contain private, protected and public members. • By default, all items defined in a class are private. • Making one class a friend of another exposes the implementation details and reduces encapsulation. • The ideal is to keep as many of the details of each class hidden from all other classes as possible.
  • 17. Data Abstraction • 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. • Thus, we can say a television clearly separates its internal implementation from its external interface and you can play with its interfaces like the power button, channel changer, and volume control without having zero knowledge of its internals.