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;



class test{
public :
int day;
int month;
int year;
void main()
class test a;
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;

Result :-
class in C++

Follow Us

Contact Us


Back to Top