Java Object Basics: Understanding Objects and Reference Variables

Day 40 – Java 2026: Smart, Stable & Still the Future Topic: Object in Java (Core of OOP) What is an Object? An object is a runtime instance of a class that represents a real-world entity. It contains: • State (variables) • Behavior (methods) • Identity (unique memory location) Steps to Create an Object Declare a reference variable Create an object using the new keyword Assign object to reference Student s1 = new Student(); Reference Variable A reference variable stores the memory address of an object, not the actual object. It is used to access the object. Example: s1 → reference variable new Student() → object Declaration and Initialization Declaration only Student s1; Initialization only s1 = new Student(); Declaration + Initialization Student s1 = new Student(); Object vs Reference Variable FeatureObjectReference VariableMemory LocationHeapStackStoresActual dataAddress of objectCreated Usingnew keywordClass typeExamplenew Student()s1Key Points • One class can create multiple objects • Each object has separate memory • Reference variable points to object • Objects are created at runtime • Java programs work using objects Simple Example class Student { String name; } public class Main { public static void main(String[] args) { Student s1 = new Student(); s1.name = "Sneha"; System.out.println(s1.name); } } Key Takeaway: Object = Real entity Reference = Way to access that entity #Java #40 #OOP #LearnJava #JavaDeveloper #Programming #100DaysOfCode #CareerGrowth

  • diagram

To view or add a comment, sign in

Explore content categories