SlideShare a Scribd company logo
2
Presentation on class and object
Mashkura Farhat; ID:180110
Enam Khan; ID:180107
Sadia Afreen Farha ; ID:180116
Presented by Presented to
Prafulla Kumar Saha
Lecturer
Department of Computer Science & Engineering
Daffodil Institute of IT(DIIT)
Most read
3
Presentation on class and object in Object Oriented programming.
Most read
5
Specifying a class
Specification of a class consists of two parts:
– Class declaration
– Function definition
Most read
!
Presentation on class and object
Mashkura Farhat; ID:180110
Enam Khan; ID:180107
Sadia Afreen Farha ; ID:180116
Presented by Presented to
Prafulla Kumar Saha
Lecturer
Department of Computer Science & Engineering
Daffodil Institute of IT(DIIT)
Presentation on class and object in Object Oriented programming.
What is class?
A class is kind of a blueprint
or template that refer to the
methods and attributes that
will be in each object
Specifying a class
Specification of a class consists of two parts:
– Class declaration
– Function definition
• The class specification starts with a
keyword “class”, followed by a class-
name.
• The class-name is an identifier
• The body of class is enclosed within
braces and terminated by a
semicolon
• The functions and variables are
collectively called class members.
• The variables are called data
members while the functions are
called member functions
• The two keywords private and
public are termed as access-specifiers
or visibility labels.
• They are followed by colon
class class_name
{
private:
variable declarations
function declarations
public:
variable declarations
function declarations
};
Characteristics of access specifies (private, public and
protected
• Private section of a class can have both data members and member functions,
usually data members are made private for data security.
• It is not mandatory that private section has to declared first in the class and then
the public section.
• If no member access specifies is specified then by default the members are
private for the class.
• There may be any number of private, public or protected section in a class
declaration.
• Protected specifies is used for declaring the class members which can be
accessed by its own class and its derived class
What is objects?
• Object: A class provides the blueprints for objects, so basically an object is
created from a class. Object can be called as an instance of a class. When class is
defined, no memory is allocated but when it is instantiated memory will be
allocated
• The definition of class does not cause any storage to be allocated. Storage is only
allocated when object of class type is defined
• Following statements declare two objects of class Box:
• Box Box1;
• Box Box2;
Syntax of defining objects of a
class
• Class className objectName
• Class : keyword
• ClassName : user defined class name
• User defined object name
• Objects can be created as follows:
class employee
{
int id;
char name[20];
public:
void getname();
void putname();
}e1, e2, e3;
Syntax of accessing data members of
class
•ObjectName : Data member
•ObjectName : user defined object
name
•“.” : member access
operator
•Data member : data member of a class.
Example:
class A
{
int x, y;
void fu1();
public:
int z;
void fu2();
};
--------------------------
A obj1;
obj1.x=0; //generates error since x is private and can be accessed only though member functions
obj1.z=0; //valid
obj1.fu1(); //generates error since fu1() is private
obj1.fu2(); //valid
Member Function
Member function’s name is visible outside the class.
 It can be defined inside or outside the class.
 It can have access to private, public and protected data
members of its class, but cannot access private data
members of another class
Outside the Class:
• In this approach, the member functions are only declared inside the class,
whereas its definition is written outside the class.
• General form:
Return-type class-name::function-name(argument-list)
{ ------------
------------ // function body
------------
}
Inside the class:
• Function body can be included in the class itself by replacing function declaration by function definition.
• If it is done, the function is treated as an inline function.
Example:
class A
{
int a, b;
public:
void getdata()
{
cin>>a>>b;
}
};
Nested Member Functions: a member function can be called by using its name inside another
member function of the same class. This is known as “Nesting Of Member Functions” .
Example: #include<iostream.h>
class addition
{
int a, b, sum;
public:
void read();
void show();
int add();
};
void addition::read()
{
cout<<“enter a, and b”;
cin>>a>>b;
}
void addition::add()
{
return(a+b);
}
void addition ::show()
{
sum=add(); // nesting of function
. cout<<endl<<“sum of a and b is :” <<sum;
}
main()
{
addition a1; a1.read();
a1.show();
return(0);
}
Output:
Enter a and b: 2 3
Sum of a and b is: 5
Private Member Functions:
we may need to make a function a private to hide them from outside world . Private member
functions can only be called by another function that is a member of its class.
Example:
class A
{
int a, b;
void read(); //private member function
public: void update();
void write();
};
void A :: update()
{
read(); //called from update() function. no object used.
}
Friend
function
• 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.
• To declare a function as a friend of a class, precede the function prototype in the class definition with
keyword friend as follows −
class Box {
double width;
public:
double length;
friend void printWidth( Box box );
void setWidth( double wid );
};
A member function that is defined inside it’s class member list, is called an
inline member function.
Example:
static inline void swap(int *m, int *n)
{
int tmp = *m;
*m = *n;
*n = tmp;
}
Inline function:
Thank You

More Related Content

What's hot (20)

DMsuite Static & Dynamic Data Masking Overview
DMsuite Static & Dynamic Data Masking OverviewDMsuite Static & Dynamic Data Masking Overview
DMsuite Static & Dynamic Data Masking Overview
Axis Technology, LLC
 
FORESTS
FORESTSFORESTS
FORESTS
MSharmilaDeviITDEPT
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 
Data base management system
Data base management systemData base management system
Data base management system
Navneet Jingar
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
Docent Education
 
Friend Function
Friend FunctionFriend Function
Friend Function
Mehak Tawakley
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
Nishant Munjal
 
Chapter 1 big data
Chapter 1 big dataChapter 1 big data
Chapter 1 big data
Prof .Pragati Khade
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization
Uma mohan
 
Isam
IsamIsam
Isam
Javed Khan
 
multilevel security Database
 multilevel security Database multilevel security Database
multilevel security Database
VrundaBhavsar
 
System_Planning_And_The_Initial_Investigation
System_Planning_And_The_Initial_InvestigationSystem_Planning_And_The_Initial_Investigation
System_Planning_And_The_Initial_Investigation
Swapnil Walde
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Database recovery
Database recoveryDatabase recovery
Database recovery
Student
 
Python programming : Abstract classes interfaces
Python programming : Abstract classes interfacesPython programming : Abstract classes interfaces
Python programming : Abstract classes interfaces
Emertxe Information Technologies Pvt Ltd
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
koolkampus
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
11 Database Concepts
11 Database Concepts11 Database Concepts
11 Database Concepts
Praveen M Jigajinni
 
Database system utilities by dinesh
Database system utilities by dineshDatabase system utilities by dinesh
Database system utilities by dinesh
Dinesh Kumar
 
DMsuite Static & Dynamic Data Masking Overview
DMsuite Static & Dynamic Data Masking OverviewDMsuite Static & Dynamic Data Masking Overview
DMsuite Static & Dynamic Data Masking Overview
Axis Technology, LLC
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
maryeem
 
Data base management system
Data base management systemData base management system
Data base management system
Navneet Jingar
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization
Uma mohan
 
multilevel security Database
 multilevel security Database multilevel security Database
multilevel security Database
VrundaBhavsar
 
System_Planning_And_The_Initial_Investigation
System_Planning_And_The_Initial_InvestigationSystem_Planning_And_The_Initial_Investigation
System_Planning_And_The_Initial_Investigation
Swapnil Walde
 
Database recovery
Database recoveryDatabase recovery
Database recovery
Student
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
1. Introduction to DBMS
1. Introduction to DBMS1. Introduction to DBMS
1. Introduction to DBMS
koolkampus
 
Database system utilities by dinesh
Database system utilities by dineshDatabase system utilities by dinesh
Database system utilities by dinesh
Dinesh Kumar
 

Similar to Presentation on class and object in Object Oriented programming. (20)

C++ Notes
C++ NotesC++ Notes
C++ Notes
MOHAMED RIYAZUDEEN
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
Praveen M Jigajinni
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Boro
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.pptcpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Shailendra Veeru
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
secondakay
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
class c++
class c++class c++
class c++
vinay chauhan
 
Class and objects
Class and objectsClass and objects
Class and objects
nafisa rahman
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
Shweta Shah
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
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
DSMS Group of Institutes
 
22 scheme OOPs with C++ BCS306B_module1.pdf
22 scheme  OOPs with C++ BCS306B_module1.pdf22 scheme  OOPs with C++ BCS306B_module1.pdf
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Boro
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.pptcpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
secondakay
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
Shweta Shah
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
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
DSMS Group of Institutes
 
22 scheme OOPs with C++ BCS306B_module1.pdf
22 scheme  OOPs with C++ BCS306B_module1.pdf22 scheme  OOPs with C++ BCS306B_module1.pdf
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
Ad

Recently uploaded (20)

june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Ad

Presentation on class and object in Object Oriented programming.

  • 1. !
  • 2. Presentation on class and object Mashkura Farhat; ID:180110 Enam Khan; ID:180107 Sadia Afreen Farha ; ID:180116 Presented by Presented to Prafulla Kumar Saha Lecturer Department of Computer Science & Engineering Daffodil Institute of IT(DIIT)
  • 4. What is class? A class is kind of a blueprint or template that refer to the methods and attributes that will be in each object
  • 5. Specifying a class Specification of a class consists of two parts: – Class declaration – Function definition
  • 6. • The class specification starts with a keyword “class”, followed by a class- name. • The class-name is an identifier • The body of class is enclosed within braces and terminated by a semicolon • The functions and variables are collectively called class members. • The variables are called data members while the functions are called member functions • The two keywords private and public are termed as access-specifiers or visibility labels. • They are followed by colon class class_name { private: variable declarations function declarations public: variable declarations function declarations };
  • 7. Characteristics of access specifies (private, public and protected • Private section of a class can have both data members and member functions, usually data members are made private for data security. • It is not mandatory that private section has to declared first in the class and then the public section. • If no member access specifies is specified then by default the members are private for the class. • There may be any number of private, public or protected section in a class declaration. • Protected specifies is used for declaring the class members which can be accessed by its own class and its derived class
  • 8. What is objects? • Object: A class provides the blueprints for objects, so basically an object is created from a class. Object can be called as an instance of a class. When class is defined, no memory is allocated but when it is instantiated memory will be allocated • The definition of class does not cause any storage to be allocated. Storage is only allocated when object of class type is defined • Following statements declare two objects of class Box: • Box Box1; • Box Box2;
  • 9. Syntax of defining objects of a class • Class className objectName • Class : keyword • ClassName : user defined class name • User defined object name • Objects can be created as follows: class employee { int id; char name[20]; public: void getname(); void putname(); }e1, e2, e3;
  • 10. Syntax of accessing data members of class •ObjectName : Data member •ObjectName : user defined object name •“.” : member access operator •Data member : data member of a class.
  • 11. Example: class A { int x, y; void fu1(); public: int z; void fu2(); }; -------------------------- A obj1; obj1.x=0; //generates error since x is private and can be accessed only though member functions obj1.z=0; //valid obj1.fu1(); //generates error since fu1() is private obj1.fu2(); //valid
  • 12. Member Function Member function’s name is visible outside the class.  It can be defined inside or outside the class.  It can have access to private, public and protected data members of its class, but cannot access private data members of another class
  • 13. Outside the Class: • In this approach, the member functions are only declared inside the class, whereas its definition is written outside the class. • General form: Return-type class-name::function-name(argument-list) { ------------ ------------ // function body ------------ } Inside the class: • Function body can be included in the class itself by replacing function declaration by function definition. • If it is done, the function is treated as an inline function. Example: class A { int a, b; public: void getdata() { cin>>a>>b; } };
  • 14. Nested Member Functions: a member function can be called by using its name inside another member function of the same class. This is known as “Nesting Of Member Functions” . Example: #include<iostream.h> class addition { int a, b, sum; public: void read(); void show(); int add(); }; void addition::read() { cout<<“enter a, and b”; cin>>a>>b; } void addition::add() { return(a+b); } void addition ::show() { sum=add(); // nesting of function . cout<<endl<<“sum of a and b is :” <<sum; } main() { addition a1; a1.read(); a1.show(); return(0); } Output: Enter a and b: 2 3 Sum of a and b is: 5
  • 15. Private Member Functions: we may need to make a function a private to hide them from outside world . Private member functions can only be called by another function that is a member of its class. Example: class A { int a, b; void read(); //private member function public: void update(); void write(); }; void A :: update() { read(); //called from update() function. no object used. }
  • 16. Friend function • 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. • To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows − class Box { double width; public: double length; friend void printWidth( Box box ); void setWidth( double wid ); };
  • 17. A member function that is defined inside it’s class member list, is called an inline member function. Example: static inline void swap(int *m, int *n) { int tmp = *m; *m = *n; *n = tmp; } Inline function: