C++ Class

A C++ Class is a user defined data type which holds both the data and function. The internal data of a class is called member data and the functions are called member functions. The variables of a class is called object.

Accessibility :-

C++ offer three levels of accessibility, namely public,
private, protected.

public :-
Member of a class can be accessed by part of a program.
Protected :-
member within a class can be accessed by member function declared by
that class and any classes “inherited ” from that class.

Private :-

Members within a class can only be accessed by that class.

How to declare class :-

class abc{

int x;
int y;
}
abc a1;

Example 

#include<iostream.h>
#include<conio.h>

class test{
public :
int day;
int month;
int year;
};
void main()
{
class test a;
a.day=15;
a.month=3;
a.year=2015;
cout<<"\n Today's date is="<<a.day<<endl;
cout<<"\n Month of the year="<<a.month<<endl;
cout<<"\n year of this day="<<a.year<<endl;
getch();
}

 
Result :-
class in C++




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top