Java Oops
Intermediate Java OOP
On this page
static: Common to All Objects
01
Notes
Belongs to the class itself, not to individual instances.
Shared copy across every created object.
Example: Platform fee on Swiggy — same ₹6 for all customer carts!
Access directly via Class name: `Swiggy.platformFee`.
Static Variables & Methods
02
Notes
Static Variable: One shared memory location for all objects.
Static Method: Called directly without creating an object using `new`.
Example: Calling `UPI.pay(500)` as a direct utility function.
Rule: Static methods CANNOT directly access non-static instance variables!
Static Blocks & Memory Model
03
Notes
Static Block: Runs ONCE when the class is first loaded.
Ideal for pre-loading setup data (e.g., fetching IRCTC server settings).
Static members live in the Class level area.
Instance members live inside separate Heap objects.
final: Lock Down Changes
04
Notes
final variable: Value cannot be reassigned (like your 12-digit Aadhaar number).
final reference: Object target is locked, but internal fields can change.
final method: Cannot be overridden by any child class.
final class: Cannot be extended/inherited (e.g., standard `String` class).