Structure of a Class in C++

Estudies4you
Q12. Illustrate the structure of a class.
Answer:

Class
A class can be defined as a template that groups data and its associated functions. The class contains two parts namely, Declaration of data variables and declaration of member functions.
The data members of a class explains about the state of the class and the member function explains about the behavior of the class. There are three types of variables available for a class. They are,
(i) Local variables
(iii) Instance variables
(iii) Class variables
(i) Local Variables
Local variables are the variables that are declared inside the methods.
(ii) Instance Variables
Instance variables are the variables that are declared inside the class but outside of the methods. .
(iii) Class Variables
Class variables are the variables that are declared inside the class with static modifier and they reside outside of the method.

Structure
A class can be declared with the help of ‘class’ keyword followed by the name of the class. The syntax of a class is as follows,
class name_of_the_ class
{
//declaration of Instance variables
type data_variable1;
type data_variable2;
//declaration of functions
type function_namel (arg_list)
{
//body of function
}
type function_name2(arg_list)
{
//body of function
}
};

It is better to maintain information of one logical entity in a class.

Definition of a Class
class Student
{
int stdId;
int stdName;
void getStdId( );
int setStdId(int sid);
}
The above definition creates a class Student. In this class, stdId and stdName are the instance variables and getStdid(), setStdId() are the member functions of the class.
To Top