What are classes ? How are they defined ?

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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


Get Latest JobsAdda.com Jobs, news & updates  via Email