What are classes ? How are they defined ?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
A class in an object oriented language is a User defined data type (UDT). A class is made up of member variables (data) and member functions (interface).
A class is created or declared using the class keyword. It defines a new type to represent a real life entity. This type is composed of data that is private to the class and accessible through the public member functions of the class.
As an analogy consider a home. A home is like an object that has a state (whether lights are on, number of walls, temperature, etc) and it provides services (like buttons to switch off the lights, a thermostat that controls the temperature). This blueprint for a home is a class since it defines the characteristics of a group of such houses.
Syntactically a class structure is similar to a structure except that everything in a class by default is made private whereas everything is public in a structure by default.
E.g. class student
{
public:
//public interface
private:
//private implementation
}
Related Articles
- What are static Data and Static Member Functions in C++ ?
- State all the class access modifiers and explain each one of them
- Explain Composition in C++ with an example
- What are objects ? What is common between all objects of a class ?
- What is Inheritance ? How is a Class Inherited in C++ ?


