can u explain me in detail regarding what is class and public
like what does each of these represent
Class and public
Hey @asaraf2407
A class is basically a user-defined data type,
for example suppose you need to represent all information of a car in a single data type(group), and you want to stor information of various cars, then you define a car data type, now you want to store speed limit and mileage, these are the variables of the class car,
You make a class car like
class Car{
public:
int speed_limit;
int mileage;
};
Now you can store info of various cars in this car data type, which can store speed limit and mileage of each car. A class can also have functions.
So basically:
A class is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class.
-A Class is a user defined data-type which has data members and member functions.
-Data members are the data variables and member functions are the functions used to manipulate these variables and together these data members and member functions defines the properties and behavior of the objects in a Class.
-In the above example of class Car, the data member will be speed limit, mileage etc and member functions can be apply brakes, increase speed etc.
Public:
The data members and member functions declared public can be accessed by other classes too. The public members of a class can be accessed from anywhere in the program using the direct member access operator (.) with the object of that class.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.