What is an object in Java
Object is an instance of a
class while class is a blueprint of an object. An
object represents the
class and consists of properties and behavior.
Properties refer to the fields declared with in class and behavior represents to
the methods available in the class.
In real world, we can understand object as a cell phone that has its properties
like: name, cost, color etc and behavior like calling, chatting etc.
So we can say that object is a real world entity. Some real world objects are:
ball, fan, car etc.
• Object reference
– an identifier of the object
• Instantiating an object
– creating an object of a class; assigns initial values to the object data
– Objects need to be instantiated before being used
• Instance of the class
– an object after instantiation
There is a syntax to create an object in the Java.
Java Object Syntax
Here, className is
the name of class that can be anything like: Student that we declared in the
above example.
variable_name is name of reference variable that is used to hold the
reference of created object.
The new is
a keyword which is used to allocate memory for the object.
|