Object-Oriented Programming (OOP) is a software programming paradigm based on the concept of "objects"—entities that bundle data attributes (state) together with methods that manipulate that data (behavior). OOP revolutionized software engineering by modeling code directly after real-world systems.
Figure 5: Architectural Overview of the 4 Pillars of Java OOP: Encapsulation, Abstraction, Inheritance, and Polymorphism.
Encapsulation is the technique of wrapping class fields (variables) and methods together into a single cohesive unit, while restricting direct external access to sensitive fields using the private modifier. Access is provided exclusively through verified public getter and setter methods.
Abstraction focuses on exposing WHAT an object does while hiding the underlying HOW it accomplishes it. For example, when you press the brake pedal in a car, you know the car stops; you do not need to understand the hydraulic fluid dynamics or caliper pressure. In Java, abstraction is achieved via abstract classes and interfaces.
Inheritance is the mechanism by which a child subclass inherits the state and methods of an existing parent superclass using the extends keyword. It models natural IS-A relationships (e.g., A Car IS-A Vehicle) and eliminates duplicate boilerplate code across systems.
Polymorphism enables a single interface or parent reference to trigger different underlying behaviors at runtime. It is divided into Compile-Time Polymorphism (Method Overloading) and Runtime Polymorphism (Method Overriding & Dynamic Method Dispatch).
| Feature | Procedural (e.g. C) | Object-Oriented (Java) |
|---|---|---|
| Primary Unit | Functions / Procedures | Classes and Objects |
| Data Security | Low: Global data can be freely accessed and mutated anywhere | High: Encapsulation hides state behind access modifiers |
| Approach | Top-Down approach | Bottom-Up approach |
| Code Reuse | Limited to function calls | Extensive via Inheritance and Polymorphism |
| Real-World Modeling | Difficult to map to business concepts | Natural mapping to business entities and domains |
Exam Question: "What is the difference between an Object and a Class?"
Master Answer: A Class is a logical template or blueprint that defines the structure and behavior of an entity; it occupies no memory for instance state. An Object is a physical instance of a class instantiated in Heap memory using new, possessing concrete values for its state attributes.
Now let us examine how classes and objects are instantiated and how their memory is allocated on the Stack vs Heap. Proceed to: Java Classes & Objects →
Accelerate your Java mastery by studying these tightly connected core tutorials:
Instantiating objects on the Heap.
Data hiding and getters/setters.
Code reuse with 'extends' and 'super'.
Dynamic method dispatch.