SlideShare a Scribd company logo
2
Most read
3
Most read
4
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

PPTX
Friend function
PDF
Class and object in C++ By Pawan Thakur
PDF
chapter-7-classes-and-objects.pdf
PDF
Python tutorial
PPTX
OOP C++
PPT
C++ Function
PPTX
Virtual base class
PPTX
Input processing and output in Python
Friend function
Class and object in C++ By Pawan Thakur
chapter-7-classes-and-objects.pdf
Python tutorial
OOP C++
C++ Function
Virtual base class
Input processing and output in Python

What's hot (20)

PPT
inhertance c++
PPTX
Pointer in C++
PDF
Python Programming - Files & Exceptions
PPTX
Python-oop
PPTX
sSCOPE RESOLUTION OPERATOR.pptx
PPTX
Stream classes in C++
PPTX
Python Exception Handling
PPT
Lecture 16 - Multi dimensional Array
PPTX
Pointers,virtual functions and polymorphism cpp
PPT
C++ Language
PPTX
class and objects
PDF
Friend function in c++
PPTX
Polymorphism in c++
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
PPTX
PDF
Operator overloading
PPTX
Pointers, virtual function and polymorphism
PPTX
Introduction Of C++
PDF
C++ Tokens
inhertance c++
Pointer in C++
Python Programming - Files & Exceptions
Python-oop
sSCOPE RESOLUTION OPERATOR.pptx
Stream classes in C++
Python Exception Handling
Lecture 16 - Multi dimensional Array
Pointers,virtual functions and polymorphism cpp
C++ Language
class and objects
Friend function in c++
Polymorphism in c++
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Operator overloading
Pointers, virtual function and polymorphism
Introduction Of C++
C++ Tokens
Ad

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

PPT
Object and class presentation
PPTX
Lecture 2 (1)
PPTX
Class and object
PPT
classes data type for Btech students.ppt
PPTX
class c++
PPSX
Arre tari mano bhosko ka pikina tari ma no piko
PDF
22 scheme OOPs with C++ BCS306B_module1.pdf
PDF
PDF
Class and object
PPT
Classes, objects and methods
PPTX
Classes and objects
PPTX
OOPs & C++ UNIT 3
PPTX
Class and objects
PPTX
PPT
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
PPTX
concepts of object and classes in OOPS.pptx
PPT
Classes and objects
PDF
Object Oriented Programming using C++ - Part 2
PPT
Class and object in C++
PPTX
Data members and member functions
Object and class presentation
Lecture 2 (1)
Class and object
classes data type for Btech students.ppt
class c++
Arre tari mano bhosko ka pikina tari ma no piko
22 scheme OOPs with C++ BCS306B_module1.pdf
Class and object
Classes, objects and methods
Classes and objects
OOPs & C++ UNIT 3
Class and objects
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
concepts of object and classes in OOPS.pptx
Classes and objects
Object Oriented Programming using C++ - Part 2
Class and object in C++
Data members and member functions
Ad

Recently uploaded (20)

PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PDF
Types of Literary Text: Poetry and Prose
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
PPTX
ACUTE NASOPHARYNGITIS. pptx
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
Skill Development Program For Physiotherapy Students by SRY.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
Revamp in MTO Odoo 18 Inventory - Odoo Slides
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Types of Literary Text: Poetry and Prose
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
How to Manage Loyalty Points in Odoo 18 Sales
Cardiovascular Pharmacology for pharmacy students.pptx
Introduction and Scope of Bichemistry.pptx
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Information Texts_Infographic on Forgetting Curve.pptx
ACUTE NASOPHARYNGITIS. pptx
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
Open Quiz Monsoon Mind Game Prelims.pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
UPPER GASTRO INTESTINAL DISORDER.docx

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: