The easiest way to explain the difference between an object and a class would be through an example.
Suppose that you created a class called Counter. This class is very simple and only contains one PRIVATE DATA MEMBER called Current Count of type unsigned int. Also, suppose that this class has two PUBLIC MEMBER FUNCTIONS. One, called Increment Count, simply increments the current value of Current Count by one. The other member function is called Return Current Count and simply returns the value of Current Count data member.
Now that you have created this class you wish to use it in your program, so that let's suppose when a button INCREMENT is pressed value of CurrentCount is incremented and when button SHOW VALUE is pressed the current value of CurrentCount is displayed.
In order to use this class you must create an object of the class in the button click function. Once an object of the class is made you can access the public functions (IncrementCount and ReturnCurrentCount ) using the dot operator.
An example of this would be:
Counter myCounter;
myCounter.IncrementCount ();
Response.write (ReturnCurrentCount());
Hence, a class is a user-defined data type. You can create your own class with data members and member functions that cater to your programming need.
But, in order to use this data type that you have created you must declare (instantiate) its object, and use the DOT OPERATOR to access its public functions.
Suppose that you created a class called Counter. This class is very simple and only contains one PRIVATE DATA MEMBER called Current Count of type unsigned int. Also, suppose that this class has two PUBLIC MEMBER FUNCTIONS. One, called Increment Count, simply increments the current value of Current Count by one. The other member function is called Return Current Count and simply returns the value of Current Count data member.
Now that you have created this class you wish to use it in your program, so that let's suppose when a button INCREMENT is pressed value of CurrentCount is incremented and when button SHOW VALUE is pressed the current value of CurrentCount is displayed.
In order to use this class you must create an object of the class in the button click function. Once an object of the class is made you can access the public functions (IncrementCount and ReturnCurrentCount ) using the dot operator.
An example of this would be:
Counter myCounter;
myCounter.IncrementCount ();
Response.write (ReturnCurrentCount());
Hence, a class is a user-defined data type. You can create your own class with data members and member functions that cater to your programming need.
But, in order to use this data type that you have created you must declare (instantiate) its object, and use the DOT OPERATOR to access its public functions.