Essential OOP Keywords: static, final, super, this, volatile, transient & assert
Everything you need to know about the most tested keywords in technical interviews.
Mock tests for SSC, Banking, Railways, UPSC & state exams
Real exam pattern, negative marking and a worked solution for every question.
Keywords in OOP control memory visibility, thread caching, inheritance boundaries, and object references. We examine the exact interview definitions from pages 11-20 of the curriculum.
1. The static Keyword (Variables, Methods, and Static Blocks)#
• Static Variable: Class-level variable stored in static memory. Shared across all instances.
• Static Method: Belongs to the class, not an object. Can be invoked directly as `ClassName.method()`. Cannot access non-static instance fields or use `this`.
• Static Block (Tricky Question 16): `static { ... }` block executed once when the class is first loaded into memory by the classloader, prior to any constructors running.
2. The super and this Keywords#
• this: Refers to the current instance of the class. Disambiguates instance variables from parameter variables with identical names (`this.age = age`).
• super: Refers to the immediate parent class object. Used to invoke parent constructors (`super(...)`) or overridden parent methods (`super.render()`).
Practise placement aptitude on the real test pattern
TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.
3. The final Keyword#
Tricky Question 8: The `final` keyword serves three distinct enforcement roles:
• final variable: Makes the value constant; cannot be modified once initialized.
• final method: Prevents method overriding in any subclasses.
• final class: Prevents inheritance entirely (no class can extend it, e.g. `java.lang.String`).
4. Hardware & Memory Keywords: volatile & transient#
• volatile (Tricky Question 23): Ensures that a variable’s value is always read from and written directly to main RAM, bypassing CPU local L1/L2 caches. Essential for thread visibility without locking overhead.
• transient (Tricky Question 25): Instructs the serialization engine NOT to serialize this variable into a byte stream. Useful for passwords or temporary runtime handles.
5. The assert and var Keywords#
• assert (Tricky Question 36): Used for internal testing and debugging to verify invariants (`assert x > 0 : "Invalid";`). Throws `AssertionError` if false.
• var (Tricky Question 38): Enables local variable type inference in modern Java 10+, allowing the compiler to deduce the variable type based on the assigned expression.
Test Your Concept Mastery
Verify your retention on: Essential OOP Keywords: static, final, super, this, volatile, transient & assert
What is the purpose of the volatile keyword in Java?
Ready for a full proctored assessment?
Take a free quick test on the real exam pattern, with a worked solution for every question.