🧭 Foundations

Principles of OOP

⏱ 2 hr3 topicsInteractive
🎯 By the end: You can contrast POP with OOP and explain the four pillars of object-oriented programming with simple examples.

Before writing Java, it helps to understand the style of programming it uses. Java is object-oriented — programs are built around objects rather than just a list of steps. This chapter introduces that idea (ICSE Class 9).

1POP vs OOP

There are two big ways to structure a program:

POP (Procedure-Oriented)OOP (Object-Oriented)
Built aroundFunctions/procedures (steps)Objects (data + actions together)
Data isOften shared/global — less protectedKept inside objects — protected
ApproachTop-downBottom-up (build objects, combine them)
Example languagesC, early BASICJava, C++, Python
POP focuses on "what steps to do"; OOP focuses on "what things (objects) exist and how they behave." OOP suits large programs because each object keeps its own data safe.
Key points
  • POP is built around procedures/functions (steps); OOP is built around objects (data + actions together).
  • In OOP, data is kept inside objects and protected, not shared globally.
  • Java, C++ and Python are object-oriented; C is procedure-oriented.

2The four pillars of OOP

OOP rests on four core ideas:

PillarMeans
AbstractionShowing only the essential features and hiding the complex details (you drive a car without knowing the engine internals)
EncapsulationWrapping data and the methods that use it together inside an object, and protecting the data
InheritanceA new class can reuse (inherit) the features of an existing class (a Car inherits from Vehicle)
PolymorphismOne name behaving in different ways (the same method works for different types)
Easy memory aid: A PIEAbstraction, Polymorphism, Inheritance, Encapsulation.
Key points
  • Abstraction shows essentials and hides details; Encapsulation wraps data + methods together and protects data.
  • Inheritance lets a new class reuse an existing class's features; Polymorphism lets one name behave in different ways.
  • Remember A-PIE: Abstraction, Polymorphism, Inheritance, Encapsulation.

3OOP in real life

OOP models the real world. Think of a Car:

  • State (data): colour, speed, fuel.
  • Behaviour (actions): start(), accelerate(), brake().

Every real car is an object built from the Car class (the design). The pillars show up naturally:

  • Abstraction — you press the accelerator; you don't need to know the engine details.
  • Encapsulation — the fuel level is kept inside the car, changed only through proper actions.
  • Inheritance — a SportsCar is a Car with extra features.
  • Polymorphism — "start" works for a Car, a Bike or a Truck, each in its own way.
Key points
  • OOP models real entities as objects with state (data) and behaviour (actions).
  • A class is the design; each real thing is an object made from it.
  • The four pillars appear naturally — e.g. a SportsCar inherits from Car (inheritance).

★ Practical: model with OOP

On paper, design an object-oriented model:

  1. Pick a real thing (e.g. a Mobile Phone). List its state (data) and behaviour (actions).
  2. Name the class and one object you'd create from it.
  3. Give one example each of abstraction and encapsulation for your object.
  4. Suggest a class that could inherit from yours.

Ready for the chapter test?

Answer 5 questions. Score 60% or more to mark this chapter complete.

Start the test →

💡 Log in to save your progress and earn the certificate.