TOPIC:
Class And Object.
CONCEPT:
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
DEFINITION OF CLASS
Example: Fruit- Class
Mango- Object
DECLARATION OF
CLASS
-Class Tag Name
-Data member
-Member Function
-Program Access Level
a) Private
b) Public
SYNTAX OF CLASS
Class class-name
{
private:
data member
public:
member function
};
DEFINITION OF OBJECT
Object may represent
- A person
- A place
- A bank account
- A table
ACCESSING A MEMBER FUNCTION
The general format is allow:
1.Object-name.data member
2.Object-name.member function
CLASS METHOD DEFINITION
- The member function Is
defined a two types :
i. Inside the class definition
ii. Outside the class definition
OUTSIDE THE CLASS DEFINITION
Syntax:
return-type class-name ::
function-name(argument
declaration)
{
function body;
}
ARRAYS AND CLASSES
Arrays and Classes have two
types of relationship:
1. Array with class
2. Array of objects
ARRAY WITH CLASS
Syntax:
class class-name
{
private:
data-type array-name;
public:
data member[size];
member function;
};
class class-name object list;
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];
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
LOCAL CLASS
Example:
void test(int a) // function
{
——;
class student // local class
{
————-; // class
definition
};
———–;
student s1(); //create object
}
LOCAL CLASS
STATIC MEMBER
Example:
class item
{
static int count; // static declare
int number;
public:
void getdata();
void getcount();
};
STATIC MEMBER FUNCTION
Syntax:
Class-name :: function-name