Object
This content is for Java. Switch to the latest version for up-to-date documentation.
An object is an instance of a class, a concrete realization with specific values for the attributes defined in the class which occupies memory.
Create Object
Section titled “Create Object”// Declaration and initializationPerson person = new Person("John", 25);Object Reference
Section titled “Object Reference”In Java, variables of reference types don’t contain the actual object but instead hold a reference (memory address) to where the object is stored.
// Creating an object and assigning its referenceString text;
text = new String("Hello");Garbage Collection
Section titled “Garbage Collection”When an object no longer has any references pointing to it, it becomes eligible for garbage collection:
Person person = new Person("John", 25);person = new Person("Jane", 28); // Original "John" object is now unreachable