Page 117 - Cs_withBlue_J_C11_Flipbook
P. 117
5.2.2 Properties of Class and Object
Class and object have the following properties:
• Class is an object factory: Factories are the places that produce products of the same kind. A class acts as a factory
as by using it, similar types of objects are created with different characteristics and common behaviours. We can
also say a class is a blueprint of objects. Hence, a class is called an object factory.
• Object is an instance of a class: As soon as an object is created in Java, it acquires memory in RAM, but this does
not happen while defining a class. Thus, objects are the physical existence of the class.
We know data types such as int, long, float, etc. are predefined classes in Java. Similarly, user-defined classes create
objects that contain all the properties and methods of those classes, and also acquire memory.
Thus, we can say an object is an instance of a class.
• Class is a user-defined data type: A user-defined data type is a derived data type depending on some existing data
types.
A Java program is made up of classes. And each class is made up of some attributes (data members) which are
predefined data types. And while creating an object of a class, we are basically defining a variable that has the size
of the total bytes of the predefined data types. Thus, we can say a class is a user-defined data type.
5.2.3 Difference between Class and Object
The differences between class and object are given in the table and also shown in the picture below:
Class Object
A class is a blueprint to create similar kinds of objects. An object is a unique entity.
No memory is occupied when a class is created. As soon as the object is created, memory is initialised.
Class is a user-defined data type. Object is a variable of the user-defined data type known
as class.
Class is the logical representation of data. Object is the physical representation of data.
Class is created once in a program. Object can be created many times as and whenever
required just by utilising the name of the class.
Syntax for declaring a class: Syntax for instantiating an object for a class:
class <classname> <classname> <objectname> = new
<constructor>;
{ }
ANIMAL (Class)
(Objects)
5.3 BASIC CONCEPT OF A VIRTUAL MACHINE
A Virtual Machine (VM) is a machine that uses software instead of a physical computer to execute programs. It creates
an environment similar to a physical computer for installing and running other software. The process of creating a
software-based version of a computer is known as virtualisation.
115
Objects 115

