chaidocs
Java Oops

Foundations

Suraj Kumar Jha 7 pages 2 min read Updated Sep 29, 2026
On this page
  1. Class vs Object: The Zomato Blueprint
  2. Fields & Methods: Data and Actions
  3. Constructors: Object Setup
  4. Under the Hood: The 'new' Keyword
  5. The 'this' Keyword: Self Reference
  6. Access Modifiers: Access Control
  7. Encapsulation: Data Protection

Class vs Object: The Zomato Blueprint

01 A blank digital Zomato order form template (Class) producing multiple filled order tickets (Objects).
Notes
A Class is just a template or blueprint—it defines what data and actions an entity will have. An Object is the real, physical instance created from that blueprint. Class: A generic Zomato 'FoodOrder' design. Object: Your actual ₹350 Paneer Tikka order #9021.

Fields & Methods: Data and Actions

02 Illustration of a Swiggy delivery agent card displaying data fields on top and actionable buttons for methods at the bottom.
Notes
Fields store the state or data of an object. Methods define the behavior or actions an object can perform. Example: A Swiggy delivery object has fields like 'driverName' and 'bikeNumber', and methods like 'acceptOrder()' or 'deliverFood()'. Every object gets its own separate copy of fields.

Constructors: Object Setup

03 A Flipkart delivery box being filled with item tags right at the assembly line stage.
Notes
A constructor is a special setup block that runs automatically when an object is created. It has the exact same name as the class and no return type. Its main job is to set initial values for fields. Example: Creating a Flipkart order directly initializes 'itemName' as 'iPhone 15' and 'price' as ₹79,999.

Under the Hood: The 'new' Keyword

04 Flowchart showing Stack variable 'myPass' pointing with an arrow to a newly created Jio Cinema subscription block in Heap memory.
Notes
Step 1: 'new' allocates fresh memory in the Heap for the object. Step 2: Java sets default values (0, null, false) to all fields. Step 3: The constructor runs and fills in your actual values. Step 4: Java returns a reference variable pointing to that Heap location.

The 'this' Keyword: Self Reference

05 A PhonePe profile screen pointing an arrow back to itself labeled 'this'.
Notes
'this' refers to the current object executing the code. It helps resolve confusion when parameter names match field names (e.g., 'this.upiId = upiId'). Can also be used to trigger other methods or return the current instance. It only works inside instance methods, not static ones.

Access Modifiers: Access Control

06 A 4-tier security door system showing strict to open access permissions.
Notes
private: Accessible only inside the same class (like your UPI PIN). default: Accessible anywhere in the same package (no keyword). protected: Accessible in same package + child subclasses. public: Accessible from anywhere in the whole app.

Encapsulation: Data Protection

07 An Indian Bank ATM machine enclosing cash inside, offering a keypad (Setter) and screen (Getter) for safe access.
Notes
Encapsulation combines data and methods into one unit while hiding direct access to sensitive fields. Keep variables 'private' so no outside code can directly corrupt them. Provide 'public' Getters and Setters to read or update data safely after checking rules. Example: An ATM machine doesn't let you grab cash manually; you must use the withdraw() method.