The core concepts of object-oriented programming (OOP) are classes, objects, inheritance, encapsulation, and polymorphism. Together, they organize programs around data and the operations performed on that data.
| Concept | Meaning | Example |
|---|---|---|
| Class | A blueprint defining the attributes and methods of a type of object. | A Student class defines name, grade, and calculateAverage(). |
| Object | A specific instance of a class, with its own attribute values. | student1 is a Student object whose name is Ana. |
| Inheritance | A class acquires attributes and methods from another class. This represents an “is-a” relationship. | IBStudent inherits from Student. |
| Encapsulation | Data and the methods that operate on it are bundled together, while direct access to internal data is restricted. | A private grade attribute is accessed using getter and setter methods. |
| Polymorphism | The same method interface produces different behavior depending on the object or class involved. | Different subclasses implement calculateFees() differently. |
A class combines an object’s state, represented by attributes, and behaviour, represented by methods. When a constructor creates an object, each object receives its own state while using the structure and methods defined by the class.
Encapsulation protects an object’s internal state and reduces unintended changes. For example, a setter method can validate that a grade is within an acceptable range before updating a private attribute.
Inheritance promotes code reuse because a subclass can use or extend features from a superclass. Polymorphism often works with inheritance: subclasses override an inherited method, allowing the same method call to execute different implementations.
A common misconception is that a class and an object are the same. A class is the definition; an object is one instance created from that definition.
For IB Computer Science B3.1, be prepared to identify a class’s attributes, methods, constructor, and instantiated objects. In an exam response, define each requested concept precisely and use a consistent example; do not describe inheritance merely as copying code or encapsulation merely as hiding all data.