Pages

Class

Class
Definition

Class : A template that describes the kinds of state and behavior that objects of its type support.

Class Contans

Data Members : Data members include members that are declared with any of the fundamental types, as well as other types, including reference, array types, bit fields, and user-defined types. A class can have members that are of a class type or are pointers or references to a class type.

Block : A block statement is a sequence of zero or more statements enclosed in braces. A block statement is generally used to group together several statements, so they can be used in a situation that requires you to use a single statement.

Constructor : A class contains constructors that are invoked to create objects from the class blueprint. Constructor declarations look like method declarations except that they use the name of the class and have no return type.

Method : When a programmer creates a class, she creates methods for that class. Methods are where the class' logic is stored. Methods are where the real work gets done. They are where algorithms get executed, and data gets manipulated.


Difference Between Instance Data Members and Static Data Members

A class is a collection of Data members. We have two types of data members they are

1. Instance / Non Static Data Members
2. Static Data Members

Instance Data Members Static Data Members
1. Instance data members are those whose memory space is created each and every time whenever an object is created. 1. Static data members are those whose memory space is created only once, whenever the class is loaded in the main memory irrespective of no of objects are created.
2. Instance data members are always meant for storing specific values. 2. Static data members are meant for storing common values.
3. Programmatically instance data members declaration should not be preceded by a keyword static. 3. Programmatically static data member declaration must be preceded by static keyword.
4. Each and every instance data member must be access with respective object name. 4. Each and every static data member must be access with respective class name.
5. Instance data members are also known as Object Level Data Members because they depend on object name and independent from class name. 5. Static data member are also known as Class Level Data Members because they depends on class name and independent from object name.