Here are few points which we need to understand about classes and objects.
To understand the difference between a class and objects, let us look at the following examples.
Student class (or type) is different. We have to use the new keyword for creating an object of non-primitive data type or user defined data type.
For e.g., in primitive types, the moment a variable is declared, the space required for that variable is also allocated.
int a = 5; a and allocates 4 bytes for that integer. But with classes (or non-primitive data types), the allocation of the space required for that object has to be done using new keyword as shown below.
If the class Student is declared like this
class Student Student mahesh = new Student(); ntr , prabhas and arjun as shown below.
Student ntr = new Student(); ntr , prabhas and arjun are called references. We will discuss more about references in Java Objects References.
![]()
|