How To Specifying a Class ?
Specifying a Class :- A class is a wait to bind the data and its associated functions together. When defining a class we are creating a new abstract data type that can be treated like any other built in data type.
Generally a class specification has two parts.
A . Class declaration.
B . Class function definition.
The class declaration describe the type and scope of its member.
The class function definition (also called member function) describe how the class functions are implemented.
General form of class declaration
class class_name
{
private:
variable declaration;
function declaration;
protected:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
· The declaration start with the keyword class followed by the class name.
· The variables declared inside the class are called data member or member variable and the functions are called member function.
· The class members are grouped into three sections – private, protected and public. The keyword private, protected and public are called visibility levels or access specifire.
· The class members declared as private can only be accessed within the class. The use of keyword private is optional, because by default all the class members are private until and unless other wise specified.
· The class member declared as protectedare accessible by the member functions within the class and any class derived from it.
· Private and protected members (data and functions) can only be accessed by member functions.
· All the publicmembers can be accessed from outside.
Example :-
class point
{
int x; // private variable declaration
int y; // private variable declaration
public:
void getpoint (int a,int b);
void getpoint (void);
};
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment