Here:
Emp e=new Emp();
e
is a reference variable that contains the address of the object that is being created in the heap area.
The reference identifier is generated as a hash code using the object’s magic method (the object has 9 methods in total), that is, the toString()
method; internally, using the toString
object method, it automatically generates a Ref ID for each object created at runtime.
Memory for an object is always reserved in the heap area of RAM. Bcz does not have an explicit pointer available in Java. Here, the ref variable points to the stack to give a reference to an object to reserve memory in Heap; The bcz object also does not know where the memory is located.
The stack segment is also part of the memory: when we pass the variable ref, then the variable ref must already be stored on the stack, then the variable ref knows which part of the head’s memory is free, and it points to the backup location of the object and is stored in the reference variable.
"new" is a text operator that helps create objects.
Emp()
: a child class of the class; if the constructor did not explicitly provide the constructor in the java program, the compiler implicitly adds the default constructor, and the reason for assigning the name of the child class as well as the class name is because where "new" can easily find out how much memory is required for non members of static data.
source share