# Class:- Class is a template which contains attributes and function.
Example:
class car
{
public:
int size;
char color;
void drive( );
void start( );
};
# Declaration of class:
👉 To declare a class we use the class keyword followed by an opening bracket ( { ) and then a list of data members and methods of the class is written. In the end, declare with a closing bracket ( } ) and semicolon ( ; ).
class car
{
public:
int size;
char color;
void drive( );
void start( );
};
# Class variables and methods
👉 In the class given above, there is a two-class variables i.e size and color and there is two-methods i.e start( ); , drive( ); .
Variable is the quantity whose value can be changed. For example:- Size of a car can be 6 fits,5, fit, 8 fits. Similarly, the color of the car can be red, blue, white, etc
Function is a module which contains a set of instruction to perform certain specific tasks.
For example:- start method can contain instructions for starting the cars, the sound of the car. Similarly, it contains some shine after starting the car. Drive methods can have instruction for changing the gayer, excletor option, etc
No comments:
Post a Comment
theengineerschoice01@gmail.com