Page 48 - CA_Blue( J )_Class9
P. 48
Similarly, in object-oriented programming, we first have to define a prototype that is known as a class. Once a class
is defined, you can create as many objects as you need, and each object will have the properties and behaviours
defined by the class, but with its own unique attribute values.
Suppose, in class 9 there are 50 students. If we create a class named NINE to represent the characteristics of a 9th-
grade student, we can create 50 objects (one for each student). All the objects will share the same properties, such
as the student's name, age, and grade (the behaviour of the class), but each object will have different characteristic
values (e.g., different names, ages, and individual attributes).
Just like a factory produces many products from the same prototype, a class in programming serves as a factory
that produces multiple objects. All the objects created from the class will share the same structure (characteristics
and behaviours) but have different specific values. This is why we can say that a class is an object factory or
blueprint for objects.
3.4.2 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.
In Java, when an object is created, it acquires memory in RAM, but this does not happen when a class is defined.
Thus, objects are the physical existence of a class.
We know data types such as int, long, float, etc. are predefined classes (that are known as primitive types) in Java.
Similarly, user-defined classes create objects that contains all the properties and methods of those classes and
these objects also acquires memory. Thus, we can say object is an instance of a class. The state of an object is
represented by the attributes of that object.
3.4.3 Class is a User-defined Data Type
A variable internally represents a memory location that is needed to store data.
In Java, variables are needed to be declared first.
For example, int x;
Here, "x" is a variable that can store int (integer) type data. But int is a predefined/primitive data type.
In Java, user-defined data types can also be created.
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. While creating a class, we are essentially defining a structure that has the size of the total
bytes of the predefined data types.
For example, if we want to create an object of a class "Employee"
class Employee
{
String emp_name;
int emp_num;
double salary;
}
If the name of the object is "emp1", then the size of the object is the combined size of String, int and double. Thus,
we can say class is a user-defined data type.
46 Touchpad Computer Applications-IX

