SlideShare a Scribd company logo
1 of 21
Prepared By: Asst. Prof. Sejal Jadav
Unit-2
Classes and Objects, Constructor and Destructor
B.C.A & B.Sc.(IT) – 3
CS-13 C++ and Object Oriented
Programming
Prepared By: Asst. Prof. Sejal Jadav
B.Inside the class definition
•The actual function definition of
member function can also be inside the
class.
•When function defined inside the class,
it is treated as inline function.
Prepared By: Asst. Prof. Sejal Jadav
•Therefore all the restriction and limitation
of inline function apply to that member
function.
•Generally, only small member functions are
defined inside class.
Prepared By: Asst. Prof. Sejal Jadav
• An instance of the
class is called as
object.
class item
{
int id; float price;
public:
void getdata(int no, float p) //function definition inside class
{
id = no;
price = p;
}
void disp(){
cout << endl << "Item Code : " << id;
cout << endl << "Item Price : " << price; }
};
main()
{
item tv;
tv.getdata(21,20500.00);
tv.disp();
}
//Example: 2.class.cpp
Prepared By: Asst. Prof. Sejal Jadav
Local Class
•A class declared inside a function is
known as a local class in C++ as it is
local to that function.
•An example of a local class is given as
follows.
Prepared By: Asst. Prof. Sejal Jadav
#include<iostream>
using namespace std;
void func()
{
class LocalClass {};
}
int main()
{ return 0;}
Prepared By: Asst. Prof. Sejal Jadav
•In the above example, func() is a
function and class LocalClass is
defined inside the function. So, it is
known as a local class.
Prepared By: Asst. Prof. Sejal Jadav
•A local class name can only be used in its
function and not outside it.
•Also, the methods of a local class must be
defined inside it only. A local class cannot
have static data members but it can have
static functions.
Prepared By: Asst. Prof. Sejal Jadav
Example a local class in C++ is :
LocalClass.cpp
Prepared By: Asst. Prof. Sejal Jadav
Nested Classes
•Nested class is a class defined inside a
class, that can be used within the scope
of the class in which it is defined.
Prepared By: Asst. Prof. Sejal Jadav
•In C++ nested classes are not given
importance because of the strong and
flexible usage of inheritance.
•Its objects are accessed using
"Nest::Display”.
Prepared By: Asst. Prof. Sejal Jadav
•Let’s look at the Example: Nested.cpp
Prepared By: Asst. Prof. Sejal Jadav
Nesting of Member Functions
•Since C++ provides concept of
encapsulation, a member function of a
class can be called only by an object of that
class using a dot operator.
Prepared By: Asst. Prof. Sejal Jadav
•But here is an exception. A member
function can be called by another
member function of the same class.
Prepared By: Asst. Prof. Sejal Jadav
•And, therefore, when a member function
is called by another member function, it
is known as nesting of member
function.
•In the example the max() is nested inside
the disp() function.
Prepared By: Asst. Prof. Sejal Jadav
•Both the functions are the members of the class
num.
•Note that the max() can also be called directly
from the outside using the object of class num
and using dot operator.
Prepared By: Asst. Prof. Sejal Jadav
•Let’s look at the Example:
1. NesteMemberFun.cpp
2. nestedFun.cpp
Prepared By: Asst. Prof. Sejal Jadav
Private Member Function
•Normally all the data members are
placed in private section and all the
member functions are placed in public
section so as to provide interface
between private data of class and
outside program.
Prepared By: Asst. Prof. Sejal Jadav
•But sometimes, situation may require
that even a functions need to be
hidden from the outside program.
•Some functions which perform serious
tasks should have restricted access.
Prepared By: Asst. Prof. Sejal Jadav
•And in such situations a function is defined in
private section.
•A private function cannot be called by using dot
operator and the object of that class.
•A private can only be called by nesting it into
another function that is a member of the same
class.
Prepared By: Asst. Prof. Sejal Jadav
• Let’s look at the Example:
1. PrivateMemberFun.cpp

More Related Content

What's hot

10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to DatastructureNilesh Dalvi
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts246paa
 
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in JavaPawanMM
 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective CTiyasi Acharya
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01Jérôme Rocheteau
 
Concepts of OOPs
Concepts of OOPsConcepts of OOPs
Concepts of OOPsEssay Corp
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOPMuhammad Hammad Waseem
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and OverridingMichael Heron
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetHDR1001
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++sandeep54552
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 

What's hot (20)

Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to Datastructure
 
Arrays in Java
Arrays in Java Arrays in Java
Arrays in Java
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
8. String
8. String8. String
8. String
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 
Session 04 - Arrays in Java
Session 04 - Arrays in JavaSession 04 - Arrays in Java
Session 04 - Arrays in Java
 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective C
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
 
Concepts of OOPs
Concepts of OOPsConcepts of OOPs
Concepts of OOPs
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 

Similar to C++ unit-2-part-3

Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxrayanbabur
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5Jadavsejal
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3Jadavsejal
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptxsyedabbas594247
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objectskhaliledapal
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentationnafisa rahman
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructorsanitashinde33
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesDigitalDsms
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)Durga Devi
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsHarsh Patel
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptmanomkpsg
 

Similar to C++ unit-2-part-3 (20)

Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 
Class and objects
Class and objectsClass and objects
Class and objects
 
oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructors
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Class and object
Class and objectClass and object
Class and object
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 

More from Jadavsejal

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassJadavsejal
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event HandlingJadavsejal
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingJadavsejal
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout ManagersJadavsejal
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15Jadavsejal
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14Jadavsejal
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12Jadavsejal
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8Jadavsejal
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7Jadavsejal
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4Jadavsejal
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2Jadavsejal
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1Jadavsejal
 
05_system architecture
05_system architecture05_system architecture
05_system architectureJadavsejal
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture Jadavsejal
 
04 authentication
04 authentication04 authentication
04 authenticationJadavsejal
 

More from Jadavsejal (20)

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone Class
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event Handling
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event Handling
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout Managers
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1
 
05_system architecture
05_system architecture05_system architecture
05_system architecture
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture
 
Vpn protocols
Vpn protocolsVpn protocols
Vpn protocols
 
04 authentication
04 authentication04 authentication
04 authentication
 
03 cia
03 cia03 cia
03 cia
 
01
01 01
01
 

Recently uploaded

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

C++ unit-2-part-3

  • 1. Prepared By: Asst. Prof. Sejal Jadav Unit-2 Classes and Objects, Constructor and Destructor B.C.A & B.Sc.(IT) – 3 CS-13 C++ and Object Oriented Programming
  • 2. Prepared By: Asst. Prof. Sejal Jadav B.Inside the class definition •The actual function definition of member function can also be inside the class. •When function defined inside the class, it is treated as inline function.
  • 3. Prepared By: Asst. Prof. Sejal Jadav •Therefore all the restriction and limitation of inline function apply to that member function. •Generally, only small member functions are defined inside class.
  • 4. Prepared By: Asst. Prof. Sejal Jadav • An instance of the class is called as object. class item { int id; float price; public: void getdata(int no, float p) //function definition inside class { id = no; price = p; } void disp(){ cout << endl << "Item Code : " << id; cout << endl << "Item Price : " << price; } }; main() { item tv; tv.getdata(21,20500.00); tv.disp(); } //Example: 2.class.cpp
  • 5. Prepared By: Asst. Prof. Sejal Jadav Local Class •A class declared inside a function is known as a local class in C++ as it is local to that function. •An example of a local class is given as follows.
  • 6. Prepared By: Asst. Prof. Sejal Jadav #include<iostream> using namespace std; void func() { class LocalClass {}; } int main() { return 0;}
  • 7. Prepared By: Asst. Prof. Sejal Jadav •In the above example, func() is a function and class LocalClass is defined inside the function. So, it is known as a local class.
  • 8. Prepared By: Asst. Prof. Sejal Jadav •A local class name can only be used in its function and not outside it. •Also, the methods of a local class must be defined inside it only. A local class cannot have static data members but it can have static functions.
  • 9. Prepared By: Asst. Prof. Sejal Jadav Example a local class in C++ is : LocalClass.cpp
  • 10. Prepared By: Asst. Prof. Sejal Jadav Nested Classes •Nested class is a class defined inside a class, that can be used within the scope of the class in which it is defined.
  • 11. Prepared By: Asst. Prof. Sejal Jadav •In C++ nested classes are not given importance because of the strong and flexible usage of inheritance. •Its objects are accessed using "Nest::Display”.
  • 12. Prepared By: Asst. Prof. Sejal Jadav •Let’s look at the Example: Nested.cpp
  • 13. Prepared By: Asst. Prof. Sejal Jadav Nesting of Member Functions •Since C++ provides concept of encapsulation, a member function of a class can be called only by an object of that class using a dot operator.
  • 14. Prepared By: Asst. Prof. Sejal Jadav •But here is an exception. A member function can be called by another member function of the same class.
  • 15. Prepared By: Asst. Prof. Sejal Jadav •And, therefore, when a member function is called by another member function, it is known as nesting of member function. •In the example the max() is nested inside the disp() function.
  • 16. Prepared By: Asst. Prof. Sejal Jadav •Both the functions are the members of the class num. •Note that the max() can also be called directly from the outside using the object of class num and using dot operator.
  • 17. Prepared By: Asst. Prof. Sejal Jadav •Let’s look at the Example: 1. NesteMemberFun.cpp 2. nestedFun.cpp
  • 18. Prepared By: Asst. Prof. Sejal Jadav Private Member Function •Normally all the data members are placed in private section and all the member functions are placed in public section so as to provide interface between private data of class and outside program.
  • 19. Prepared By: Asst. Prof. Sejal Jadav •But sometimes, situation may require that even a functions need to be hidden from the outside program. •Some functions which perform serious tasks should have restricted access.
  • 20. Prepared By: Asst. Prof. Sejal Jadav •And in such situations a function is defined in private section. •A private function cannot be called by using dot operator and the object of that class. •A private can only be called by nesting it into another function that is a member of the same class.
  • 21. Prepared By: Asst. Prof. Sejal Jadav • Let’s look at the Example: 1. PrivateMemberFun.cpp