What is an object?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for OOP Concepts development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
An object is an instance of a class — a specific realization of the class blueprint created in memory at runtime. Each object has its own copy of the class's instance variables (state) and shares the class's methods (behavior). Creating objects: // From the BankAccount class: BankAccount aliceAccount = new BankAccount("1001", "Alice", 5000.0); BankAccount bobAccount = new BankAccount("1002", "Bob", 2500.0); // Each object is independent: aliceAccount.deposit(1000); // Only Alice's account changes System.out.println(aliceAccount.getBalance()); // 6000.0 System.out.println(bobAccount.getBalance()); // 2500.0 (unchanged). Object identity (reference) vs equality (value): BankAccount a1 = new BankAccount("1001", "Alice", 1000); BankAccount a2 = new BankAccount("1001", "Alice", 1000); // Same data, different objects a1 == a2 // false -- different references in memory a1.equals(a2) // true if equals() is overridden to compare content. Object state: the current values of all its attributes. State can change over time through method calls. Object behavior: methods define what the object can do. Object identity: each object has a unique identity (memory address). Encapsulation in objects: the object's internal state is protected — only changed through its methods (if fields are private). null: a special reference meaning "no object" — dereferencing null throws NullPointerException (Java) or causes undefined behavior (C++).
Pro Tip
This topic has OOP Concepts-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.