Saturday, 6 January 2018

4.2 Object creation

Everything in java treated as an object.

Syntax to create an object of a class :

A obj = new A()

A = Class name for which you want to create object
obj = Reference variable
new = keyword to create an object
A() = constructor

"new A()" is an object or you can call it instance.
obj is a reference variable which stores the address of this object.
obj is a reference variable and it is stored in a stack memory.
new A() is an object which is stored in heap memory.


No comments:

Post a Comment