Concept of Class

October 27, 2015 Posted by WithU Technologies
To create an object, we need class. So in programming
classes are the main focal point of OOP concept.

What is Class?


It describes what the object will be, but is
separate from object itself. It acts as the objects blueprint, description or
definition.

·As we know car is an object. And every specific
model of a car will definitely have a specific blue print for that model.

Now when the engineers and labours create a
new car or many new car of same model, they will not change the
blueprint(Class).

The blueprint for that car model remains
same throughout the production of that model.

·So, as like the real world, in programming also
we create the blueprint or class first and then use that class to generate that
type of object or multiple objects of the same type.

·
In programming, the term type is used to refer the class name.

Methods

·They are similar to functions.
·They act as the class behaviour.
·They perform actions and also provide return
values as like the functions do.
Example:



#include <iostream>
#include <stdlib.h>
using namespace std;

class Dev{
 // Class
Declared before using it

      public:

            void message(){  // Method as
like the functions

                  cout<<"Example of Class"<<endl;    //Outputs:
Example of Class

            }

      };

int main(){  

      Dev msg;   //Here msg
is the object which have all the members of the class defined

      msg.message();
//dot separator is used to access and call all the method of the
object

}

·
 Class definition must have followed by a semi colon (;).

·
Attributes and behaviour are to be defined
within the body of the class { body of class}.

·
To access the members, we need an access specifier.

·
Access specifier access the member from outside
the class which has been defined using the public
keyword.

·
We create the class to define attributes and behaviour.
·
So, basically it does not provide any actual data.
·
As like the blueprint, it only provides a
definition.
·
After written the class, we will write the
objects that are based upon that class or blueprint and also acts as its
specified definition for attributes and behavior.

·
Each object is called an instance of a class.
And the process of creating object is called instantiation.