Write one line of code in Java to instantiate an object of class Student with the default and the with reference name stu1
Write one line of code in Java to instantiate an object of class Student with the default and the with reference name stu1
Introduction
Reference:
In Java, a reference is a type of variable that holds the memory address of an object in the JVM's heap.
When you create an object in Java using the new
keyword, memory is allocated on the heap and a reference to that memory location is returned. This reference is stored in a variable, allowing you to access and manipulate the object's properties and methods.
Java references are automatically managed by the JVM through a mechanism known as Garbage Collection. This means that when an object is no longer referenced by any variable, the JVM automatically deallocates the memory used by that object.
In summary, references in Java are variables that hold the memory address of objects, and they are automatically managed by the JVM through Garbage Collection.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps