Class with Example

A class is an abstract data type(ADT) and it is similar to inbuilt data type. Class is used to represent an entity or object of real world. All the data members and associated functions of an object/entity are represented in a class. Classes are created through class keyword. By default domain/access specifier of class is private.
एक क्लास एक ADT(एब्सट्रैक्ट डाटा टाइप) है एवं यह इनबिल्ट डाटा टाइप के सामान ही होता है। क्लास के द्वारा वास्तविक दुनिया के ऑब्जेक्ट या एंटिटी को व्यक्त किया जाता है। ऑब्जेक्ट के सभी डाटा मेम्बेर्स एवं मेम्बर फंक्शन को क्लास के अंतर्गत दर्शाया जाता है। क्लास को class कीवर्ड की सहायता से तैयार किया जाता है। क्लास का पूर्व निर्धारित डोमेन या एक्सेस स्पेसीफायर प्राइवेट होता है। 
Specification of a class is as follows (क्लास का प्रारूप निम्न है)- 
 


Syntax-

class class_name{
variable_declaration;
----------
----------
function_declaration/definition
protected:
variable_declaration;
----------
function_declaration/definition;
public:
variable_declaration;
----------
function_declaration/definition;
}obj1, obj2 , ....,objn;

In Other Functions(अन्य फंक्शन में):-

class_name object_name;

Example-

class employee{
private:
int empid;
char empname[20];
float salary;
void grosssalary();
public:
void getemp();
void setemp();
}e1,e2;

In Other Functions (अन्य फंक्शन में):-

employee e; // object (instance) of a class

No comments:

Post a Comment