Following are some descriptions on classes and objects.
Note: The contents of all following descriptions are almost same but the presentations are different.
1. Class is a modelling for entity /
Class is a template to create objects
A class is defined with characteristics and behaviours of its objects (entities) as
a model. Using this model (class) so many objects can be created. When objects are created,
all objects get the characteristics and behaviour defined in the class.
E.g.: A rectangle object’s characteristics are length and breadth, and its behaviour
is finding area. Using the behaviour (method) area of it can be found.
2. Class is an object factory /
Class is a specification for objects
An object has two features – attributes and behaviours. A class is a mould with attributes and behaviours to create objects. We can create any number of objects using this mould, the class. So a class is an object factory.
E.g.: After defining a Rectangle class with l and b as its characteristics and area() as its behaviour we can create so many rectangle objects and find area of all of them.
3. Class is a blueprint for objects
In a class the essential characteristics and behaviours of an object are defined as a blueprint (plan). Using this blueprint we can create so many objects as we require. All these objects will have the characteristics and behaviours which are defined in the class.
E.g.: Using a blueprint of a car we can create so many cars.
4. Object encapsulates state and behaviour
A class is defined with characteristics and behaviours of its objects. When an object is created, the object gets all characteristics and behaviours defined in the class. These characteristics hold certain values, which are states. So the object encapsulates state and behaviour.
E.g.: A rectangle object’s characteristics are length and breadth, and its state can be 10 and 8. One of its behaviour is finding area. All these are defined in a class named Rectangle.
5. Class as user-defined data type
A class is defined with characteristics and behaviours as its members by a user.
This class is used as data type to create objects. Objects are varaiables of this data type (class).
E.g.: Rectangle rect = new Rectangle(); The Rectangle is a data type defined by the user
and the object rect is its variable. The = initialize 0 to l and b of rect.
6. Class is a composite data type
A class is composed with various characteristics and behaviours as its members.
So this class is a composite data type to create objects. Objects are varaiables of this data type (class).
E.g.: Rectangle rect = new Rectangle(); The Rectangle is a data type composed with length, breadth and findArea()
method. The object rect is its variable.
7. Objects are instances of a class
A class is an explanation about the characteristics and behaviours of an object. Object is an example for this explanation. That means class is a concept about the objects, and these objects are the real things. So objects are instances of a class.
E.g.: We can say that the concept of a rectangle is that it is a shape with length and breadth. When we draw one with length and breadth as 10 cm and 8 cm as an example then the real rectangle object happens.
8. Class is an abstraction for sets of objects
An object can have many characteristics and behaviours. For a particular purpose all these characteristics and behaviours need not to be defined. So a class is defined with essential characteristics and behaviours for a particular purpose without including background details. With this abstract (concept) of class definition, sets of objects can be created. So a class is abstraction for sets of objects.
E.g.: A student object has so many attributes like roll, name, marks, caste, gender, address etc. To find result we need only roll, name and marks. So we can define a Student class with these essential features.