Page 263 - CA_Blue( J )_Class10
P. 263
11.2 CLASS
A class is a blueprint to create several objects with the same properties and behaviour. If you observe things around
you, you will see that various objects have the same properties and behaviours. For example, all the dogs have the
same properties like colour, breed and name. They also have the same behaviours, like barking, eating and fetching.
Hence, Dog is a class and the different types of dogs are the objects of the Dog class.
Dog
Poodle Bulldog Rottweiler
Let us take another example: Computer is a class, and the different types of computers, like supercomputer, mainframe
computer, and minicomputer, are the objects that use the properties of the Computer class.
Computer
Supercomputer Mainframe Computer Minicomputer
Every object of a class has the same properties and behaviours that the class has. As we can create multiple objects of
a class, the class is also known as an object factory.
11.3 DIFFERENCE BETWEEN CLASS AND OBJECT
Following are the differences between a class and an object:
Class Object
A class is a logical entity. An object is a real-world entity.
A class is a blueprint to create several objects. An object is the instance of a class.
A class doesn't take any space in memory. An object takes space in memory.
11.4 CREATING OBJECTS OF A CLASS
Classes in Java are non-primitive data types that act as a blueprint for creating objects of the same type. In other
words, they are a set of instructions to build a specific type of object. An object of a class is also called an instance and
the process of creating an object of a class is called instantiation. The syntax to create an object is:
<class_name> <object_name> = new <constructor>;
For example:
Computer mainframe = new Computer( );
where mainframe is an object of the Computer class. It has all the attributes and behaviour of the Computer class.
11.4.1 Defining a Class
Following is the syntax to define a class:
class <name of class>
{
access-specifier datatype instance variable1;
access-specifier datatype instance variable2;
.
261
Class as the Basis of all Computation 261

