Topic
CLASS
AND
OBJECTS.
By Hardeep Singh
CONTENTS
Definition of Class
Declaration of class
Definition of object
Relationship of class and
object
Accessing a member
function
Arrays and classes
Class and object scope
Static data member
Static member function
By Hardeep Singh
DEFINITION OF
CLASS
Example
Fruit Mango
Class Object
By Hardeep Singh
DECLARATION OF
CLASS
Class Tag Name
Data member
Member Function
Program Access Level
a) Private
b) Public
By Hardeep Singh
SYNTAX OF CLASS
Class class-name
{
private:
data member
public:
member function
};
By Hardeep Singh
DEFINITION OF
OBJECT
Object may represent
A person
A place
A bank account
A table
By Hardeep Singh
ACCESSING A
MEMBER
FUNCTION
The general format is allow:
1.Object-name.data member
2.Object-name.member
function
By Hardeep Singh
CLASS METHOD
DEFINITION
The member function Is
defined a two types :
i. Inside the class definition
ii. Outside the class definition
By Hardeep Singh
OUTSIDE THE
CLASS DEFINITION
Syntax:
return-type class-name ::
function-name(argument
declaration)
{
function body;
}
By Hardeep Singh
ARRAYS AND
CLASSES
Arrays and Classes have two
types of relationship:
1. Array with class
2. Array of objects
By Hardeep Singh
ARRAY WITH CLASS
Syntax:
class class-name
{
private:
data-type array-name;
public:
data member[size];
member function;
};
class class-name object list;
By Hardeep Singh
ARRAY OF
OBJECTS
Syntax:
class class-name or tag-name
{
private:
data member;
member function;
public:
data member;
member function;
};
class class-name object[size];
By Hardeep Singh
CLASS AND
OBJECT SCOPE
They are two types of classes
and two types of objects as
written below:
1. Local class
2. Global class
3. Local object
4. Global object
By Hardeep Singh
LOCAL CLASS
Example:
void test(int a) // function
{
------;
class student // local class
{
-------------; // class
definition
};
-----------;
student s1(); //create object
} By Hardeep Singh
STATIC MEMBER
Example:
class item
{
static int count; // static declare
int number;
public:
void getdata();
void getcount();
}; By Hardeep Singh
STATIC MEMBER
FUNCTION
Syntax:
class-name :: function-
name;
By Hardeep Singh
Thanks
Any ?
By Hardeep Singh