What do you understand by class and object?

            Class: Class is an user-defined data type which works same as the built in data types. A class contains some variables and functions to access those variables. These stay tied together and can not be accessed by other functions of other classes without permission. In that way data of a function under variables stay secured. Objects are the variables of the class type. When objects of a class type have been declared, each object is associated with the data of that class type. For example, if we take Fruit as a class we can declare mango, banana etc as object of this class and it is the better practice to keep same functionality tied together. The syntax is as follows,

                                                            class class_name

Inside the braces of the class we will declare variables and functions of the class.

            Object: In OOP we can call objects as variables where each object may have its own variables too to operate. Objects are variables of user defined data type or class type. They may represent any item of that the program has to handle. As each class has some functions, objects declared of a class type will also be associated with the functions of the class type. Considering the following example.

class student{
    int a, b;
    void getdata();
    void calcdata();
    void display();

void main(){
    student s1, s2, s3;

When executing the above lines of codes, for each s1, s2, s3 we will have two integers a and b as s1, s2, s3 all are objects of the class student and still the data for each of them will stay safe. And also by using all these objects we can call the three functions of the class individually.

Thus the main thing about Class and Object that it reduces codes and secure data.


Never Miss What"s New !

No SPAM, only email notification if new posts were published.

Recommended Recommends


Contact Us