IB Computer Science B3.1: Fundamentals of OOP for a single class
New IB Computer Science syllabus · first exams May 2027 · Theme B · Paper 2 · SL & HL · Python and Java
B3 Object-oriented programming takes 7 hours at SL and 23 hours at HL. SL students study B3.1; HL students also study B3.2. B3.1 covers designing and coding a single class.
| Statement | Topic | Command term |
|---|---|---|
| B3.1.1 | Fundamentals of OOP | Evaluate |
| B3.1.2 | Designing classes and methods (UML) | Construct |
| B3.1.3 | Static vs non-static variables and methods | Distinguish |
| B3.1.4 | Defining classes and instantiating objects | Construct |
| B3.1.5 | Encapsulation and information hiding | Explain / Apply |
Key points
B3.1.1 OOP fundamentals (Evaluate)
- Core concepts: classes, objects, inheritance, encapsulation, polymorphism.
- Strengths: models real-world entities naturally (a library system has Book, Member and Loan classes), and makes large programs easier to reuse and maintain.
- Weaknesses: more design effort, and overkill for a short script such as a temperature converter.
B3.1.2 UML class diagrams
A three-part box: class name, then attributes (- title : String), then methods (+ isSuitableForChildren() : boolean). A - marks private members and a + marks public ones.
B3.1.3 Static vs non-static
- Instance (non-static): each object has its own copy. For example, each car has its own colour.
- Static (class): one shared copy for the whole class. For example, the number of wheels, if every car in the model has 4.
B3.1.4 Classes, objects and constructors
A class is a blueprint and an object is one instance of it. The constructor runs automatically when an object is created and sets its starting values: __init__ in Python, a method with the class's name in Java.
B3.1.5 Encapsulation and information hiding
- Make attributes private and expose public methods (getters and setters) that control access.
- This protects the object's integrity, because invalid values can't be set directly.
Exam-style question
Explain how encapsulation protects an object's state, then apply it by constructing a Password class that only allows its value to be changed if the new password is at least 8 characters long. [6]
Mark scheme
- [2] Explanation: a private attribute plus a public method applies the 8-character rule on every change, so the password can never be set to an invalid value directly.
- [4] Correct, validated code:
Python
class Password: def __init__(self, value): self.__value = value def get_value(self): return self.__value def set_value(self, new_value): if len(new_value) >= 8: self.__value = new_valueJava
public class Password { private String value; public Password(String value) { this.value = value; } public String getValue() { return value; } public void setValue(String newValue) { if (newValue.length() >= 8) { value = newValue; } }}Common mistakes that cost marks
- Making attributes public "to keep it simple". That throws away the point of encapsulation.
- Confusing a class with an object. The class is the blueprint; objects are the instances made from it.
- Making something static that each object should have its own copy of, such as a car's speed.
- Giving a one-word judgement for "Evaluate". Weigh the pros and cons for the specific scenario.
Frequently asked questions
Is B3.1 studied at SL?
Yes. B3.1 is studied at SL and HL; B3.2 (multiple classes) is HL only.
What is the double underscore in Python's self.__value?
It makes the attribute harder to access from outside the class. It's Python's way of marking an attribute as private.
Go further
- Practise B3.1 with instant marking on ExamHaus, in Python or Java. → examhaus.com
- Full B3.1 presentation and question bank with mark scheme on CS Exam Ready. → csexamready.com/resources/ib-diploma
- IB CS mock exams: Paper 2 in Python and Java. → examhaus.com/mock-exams
