SlideShare a Scribd company logo
Class And Objects
Submittedby:
Grp : Zeeb
1.Nafisa Ellahi (2016-2-17-006)
2.Jumma Nahar (2016-2-17-005)
Dept : CSE
Course Title:Object Oriented Programming(OOP-202)
Submitted To: Aysha Aziz
Prova
Cotants:
• C Structures Revisited
• Limitations of C Structure
• An Introduction to classes
• Class definition
• Specifying a class
• Creating objects
• Member Function
• Accessing class members
• Defining Member Functions
• Outside the Class
• Inside the class
• Array of objects
• Memory allocation for objects
• Objects As Function Arguments
• friend Functions and friend Classes
C Structures Revisited
• One of the unique facilities provided by C language
is structure
• It is used to group logically related data items
• It is user defined data-type and once structure type
is defined, variables of that type can be created
3
Limitations of C Structure
• They don’t allow data hiding
• Structure members can be accessed using
structure variable by any function any where in the
scope
• C does not allow the structure data type to be
treated like built-in data type
4
An Introduction to classes
• A class is a building block of OOP. It is the way to bind the data and its logically
related functions together.
• An abstract data type that can be treated like any other built in data type.
Class definition
• Class head class name_of_class.
• Class body {
• data members;
• member functions;
• };
Specifying a class
• Specification of a class consists of two parts:
– Class declaration
– Function definition
Syntax:
class class_name
{
private:
variable declarations
function declarations
public:
variable declarations
function declarations
};
7
Continue…
• The key feature of OOP is data
hiding.
• Generally, data within a class is
made private and the functions are
public.
• So, the data will be safe from
accidental manipulations, while the
functions can be accessed from
outside the class
• However, it is not necessary that
the data must be private and
functions public
8
Creating objects:
• Once a class has been declared, variables of that type can be created
by using the class name as data-type
Test t1; //memory for t1 is allocated
• This statement creates a variable t1 of type test.
• The class variables are known as objects
• t1 is called object of class test.
• More than one object of a class can be created
9
Contd…
Objects are also called instances of class
Objects can be created as follows:
class employee
{
int id;
char name[20];
public:
void getname();
void putname();
}e1, e2, e3;
10
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.
Accessing class members
• The class members are accessed using dot operator
• However it works only for the public members
• The dot operator is called member access operator
• The general format is:
• class-object.class-member;
• Eg: e1.getdata();
• The private data and functions of a class can be accessed only
through the member functions of that class
12
Defining Member Functions
• Member function can be defined in two ways
• Outside the class
• Inside the class
• The code for the function body would be identical in
both the cases i.e perform same task irrespective of
the place of definition
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
--------------
}
14
Contd…
Eg:
class A
{
int x, y;
public:
void getdata ();
// function declaration inside the class}
void A :: getdata()
{
cin>>x>>y; // function body
}
15
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
• Hence, all the restrictions that apply to inline
function, will also apply here
16
Eg:
class A
{
int a, b;
public:
void getdata()
{
cin>>a>>b;}
};
Here, getdata() is defined inside the class. So, it will act like an inline
function
A function defined outside the class can also be made ‘inline’ by using the
qualifier ‘inline’ in the header line of a function definition
17
Array of objects
• Array can be created of any datatype
• Since a class is also a user defined data-type, array
of objects can be created
• Eg: a class Employee is specified. If we have to
keep records of 20 employees in an organization
having two departments, then instead of creating 20
separate variables, we can create array of objects
as follows:
Employee dept1[10];
Employee dept2[10];
18
Memory allocation for objects
• Memory space for object is allocated when they are declared and not
when the class is specified
• The member functions are created and placed in the memory only
once, when they are defined as a part of a class specification
• All the objects belonging to the particular class will use same member
functions when objects are created
• However, the data members will hold different values for different
object, so, space for data member is allocated separately for each
object
19
friend Functions and friend Classes
friend declarations:
To declare a friend function
• Type friend before the function prototype in the class that is giving friendship
friend int myFunction( int x );
should appear in the class giving friendship
• To declare a friend class type friend class Classname in the class that is giving
friendship
• if ClassOne is granting friendship to ClassTwo friend class ClassTwo;
• should appear in ClassOne's definition
Example:
friend
class B {
friend class A ; // A is a friend of B
private:
int i;
};
class A {
public:
A(B b) {
b.i = 0; // legal access due to friendship
}
};
Thanks For Watching…
Ad

Recommended

Object and class presentation
Object and class presentation
nafisa rahman
 
C++ classes
C++ classes
Aayush Patel
 
Lecture 2 (1)
Lecture 2 (1)
zahid khan
 
class c++
class c++
vinay chauhan
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
Write First C++ class
Write First C++ class
Learn By Watch
 
Classes and objects
Classes and objects
Shailendra Veeru
 
Classes and objects till 16 aug
Classes and objects till 16 aug
shashank12march
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
C++ Notes
C++ Notes
MOHAMED RIYAZUDEEN
 
Classes and objects
Classes and objects
rajveer_Pannu
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
C++ And Object in lecture3
C++ And Object in lecture3
UniSoftCorner Pvt Ltd India.
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
4 Classes & Objects
4 Classes & Objects
Praveen M Jigajinni
 
Data members and member functions
Data members and member functions
Marlom46
 
Classes and objects
Classes and objects
Anil Kumar
 
Class and object in c++
Class and object in c++
NainaKhan28
 
Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Inheritance
Inheritance
Prof. Dr. K. Adisesha
 
Class and object in C++
Class and object in C++
rprajat007
 
Data members and member functions
Data members and member functions
Harsh Patel
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
C# classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Class or Object
Class or Object
Rahul Bathri
 
Class and object
Class and object
Prof. Dr. K. Adisesha
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 

More Related Content

What's hot (20)

CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
C++ Notes
C++ Notes
MOHAMED RIYAZUDEEN
 
Classes and objects
Classes and objects
rajveer_Pannu
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
C++ And Object in lecture3
C++ And Object in lecture3
UniSoftCorner Pvt Ltd India.
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
4 Classes & Objects
4 Classes & Objects
Praveen M Jigajinni
 
Data members and member functions
Data members and member functions
Marlom46
 
Classes and objects
Classes and objects
Anil Kumar
 
Class and object in c++
Class and object in c++
NainaKhan28
 
Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Inheritance
Inheritance
Prof. Dr. K. Adisesha
 
Class and object in C++
Class and object in C++
rprajat007
 
Data members and member functions
Data members and member functions
Harsh Patel
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
C# classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Class or Object
Class or Object
Rahul Bathri
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
Syed Faizan Hassan
 
Data members and member functions
Data members and member functions
Marlom46
 
Classes and objects
Classes and objects
Anil Kumar
 
Class and object in c++
Class and object in c++
NainaKhan28
 
Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Classes and objects
Classes and objects
Nilesh Dalvi
 
Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Class and object in C++
Class and object in C++
rprajat007
 
Data members and member functions
Data members and member functions
Harsh Patel
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 

Similar to Class and objects (20)

Class and object
Class and object
Prof. Dr. K. Adisesha
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Class object
Class object
Dr. Anand Bihari
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
Abdullah Jan
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
secondakay
 
Class objects oopm
Class objects oopm
Shweta Shah
 
oop lecture 3
oop lecture 3
Atif Khan
 
APL-2-classes and objects.ppt
APL-2-classes and objects.ppt
srividyal2
 
APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++
ProfLSrividya
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
DSMS Group of Institutes
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming Constructors & Destructors
anitashinde33
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
Classes and objects1
Classes and objects1
Vineeta Garg
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
static member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
22 scheme OOPs with C++ BCS306B_module1.pdf
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
oopusingc.pptx
oopusingc.pptx
MohammedAlobaidy16
 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptx
urvashipundir04
 
Classes, objects and methods
Classes, objects and methods
farhan amjad
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
Abdullah Jan
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
secondakay
 
Class objects oopm
Class objects oopm
Shweta Shah
 
oop lecture 3
oop lecture 3
Atif Khan
 
APL-2-classes and objects.ppt
APL-2-classes and objects.ppt
srividyal2
 
APL-2-classes and objects.ppt data structures using c++
APL-2-classes and objects.ppt data structures using c++
ProfLSrividya
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
DSMS Group of Institutes
 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming Constructors & Destructors
anitashinde33
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
Classes and objects1
Classes and objects1
Vineeta Garg
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
static member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
22 scheme OOPs with C++ BCS306B_module1.pdf
22 scheme OOPs with C++ BCS306B_module1.pdf
sindhus795217
 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptx
urvashipundir04
 
Classes, objects and methods
Classes, objects and methods
farhan amjad
 
Ad

Recently uploaded (20)

K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
Ad

Class and objects

  • 1. Class And Objects Submittedby: Grp : Zeeb 1.Nafisa Ellahi (2016-2-17-006) 2.Jumma Nahar (2016-2-17-005) Dept : CSE Course Title:Object Oriented Programming(OOP-202) Submitted To: Aysha Aziz Prova
  • 2. Cotants: • C Structures Revisited • Limitations of C Structure • An Introduction to classes • Class definition • Specifying a class • Creating objects • Member Function • Accessing class members • Defining Member Functions • Outside the Class • Inside the class • Array of objects • Memory allocation for objects • Objects As Function Arguments • friend Functions and friend Classes
  • 3. C Structures Revisited • One of the unique facilities provided by C language is structure • It is used to group logically related data items • It is user defined data-type and once structure type is defined, variables of that type can be created 3
  • 4. Limitations of C Structure • They don’t allow data hiding • Structure members can be accessed using structure variable by any function any where in the scope • C does not allow the structure data type to be treated like built-in data type 4
  • 5. An Introduction to classes • A class is a building block of OOP. It is the way to bind the data and its logically related functions together. • An abstract data type that can be treated like any other built in data type.
  • 6. Class definition • Class head class name_of_class. • Class body { • data members; • member functions; • };
  • 7. Specifying a class • Specification of a class consists of two parts: – Class declaration – Function definition Syntax: class class_name { private: variable declarations function declarations public: variable declarations function declarations }; 7
  • 8. Continue… • The key feature of OOP is data hiding. • Generally, data within a class is made private and the functions are public. • So, the data will be safe from accidental manipulations, while the functions can be accessed from outside the class • However, it is not necessary that the data must be private and functions public 8
  • 9. Creating objects: • Once a class has been declared, variables of that type can be created by using the class name as data-type Test t1; //memory for t1 is allocated • This statement creates a variable t1 of type test. • The class variables are known as objects • t1 is called object of class test. • More than one object of a class can be created 9
  • 10. Contd… Objects are also called instances of class Objects can be created as follows: class employee { int id; char name[20]; public: void getname(); void putname(); }e1, e2, e3; 10
  • 11. 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.
  • 12. Accessing class members • The class members are accessed using dot operator • However it works only for the public members • The dot operator is called member access operator • The general format is: • class-object.class-member; • Eg: e1.getdata(); • The private data and functions of a class can be accessed only through the member functions of that class 12
  • 13. Defining Member Functions • Member function can be defined in two ways • Outside the class • Inside the class • The code for the function body would be identical in both the cases i.e perform same task irrespective of the place of definition 13
  • 14. 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 -------------- } 14
  • 15. Contd… Eg: class A { int x, y; public: void getdata (); // function declaration inside the class} void A :: getdata() { cin>>x>>y; // function body } 15
  • 16. 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 • Hence, all the restrictions that apply to inline function, will also apply here 16
  • 17. Eg: class A { int a, b; public: void getdata() { cin>>a>>b;} }; Here, getdata() is defined inside the class. So, it will act like an inline function A function defined outside the class can also be made ‘inline’ by using the qualifier ‘inline’ in the header line of a function definition 17
  • 18. Array of objects • Array can be created of any datatype • Since a class is also a user defined data-type, array of objects can be created • Eg: a class Employee is specified. If we have to keep records of 20 employees in an organization having two departments, then instead of creating 20 separate variables, we can create array of objects as follows: Employee dept1[10]; Employee dept2[10]; 18
  • 19. Memory allocation for objects • Memory space for object is allocated when they are declared and not when the class is specified • The member functions are created and placed in the memory only once, when they are defined as a part of a class specification • All the objects belonging to the particular class will use same member functions when objects are created • However, the data members will hold different values for different object, so, space for data member is allocated separately for each object 19
  • 20. friend Functions and friend Classes friend declarations: To declare a friend function • Type friend before the function prototype in the class that is giving friendship friend int myFunction( int x ); should appear in the class giving friendship • To declare a friend class type friend class Classname in the class that is giving friendship • if ClassOne is granting friendship to ClassTwo friend class ClassTwo; • should appear in ClassOne's definition
  • 21. Example: friend class B { friend class A ; // A is a friend of B private: int i; }; class A { public: A(B b) { b.i = 0; // legal access due to friendship } };