Back to Topic 7.1 — OOP: a single class
7.1.5Computer Science SL5 flashcards

Encapsulation

Practice Flashcards

Flip to reveal answers
Card 1 of 57.1.5
7.1.5
Question

What is encapsulation?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All 5 Flashcards — Encapsulation

Sign up free to track progress and get spaced-repetition review schedules.

Card 1definition

Question

What is encapsulation?

Answer

Keeping an object's data private and providing public methods as the only way to reach it, so every change goes through code that can check it first rather than any part of the program writing whatever it likes.

Card 2comparison

Question

What is the difference between encapsulation and information hiding?

Answer

Encapsulation is the mechanism — private attributes, public methods. Information hiding is the principle behind it: the outside should know what a class does, not how, so the inside can be rewritten without breaking callers.

Card 3definition

Question

What are getters and setters?

Answer

A getter returns a private value; a setter changes one after checking it. Providing a getter but no setter makes a value readable from outside but not changeable.

Card 4concept

Question

Why is a setter with no checks not really encapsulation?

Answer

The data is then effectively public with extra typing. The value of encapsulation lies in the checking that happens on the way in, not in the wrapping itself.

Card 5concept

Question

How does a private attribute help when a value is wrong?

Answer

The fault must be inside that class, since nothing outside could have written it. With a public attribute, any line of the whole program could be responsible — the same argument as preferring local variables to global ones.

Track your progress with spaced repetition

Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.

Start Free
IB Computer Science Encapsulation Flashcards | 7.1.5 | Aimnova