Back to all Computer Science topics
Topic 7.2Computer Science HL25 flashcards

OOP: multiple classes

Practice Flashcards

Flip cards to reveal answers
Card 1 of 257.2.1
7.2.1
Question

What is inheritance?

Click to reveal answer

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

All Flashcards in Topic 7.2

Below are all 25 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.

7.2.15 cards

Card 1definition
Question

What is inheritance?

Answer

Defining a class as a **specialised version** of another, taking its attributes and methods and adding its own.

Card 2concept
Question

Inheritance or composition — how do you choose?

Answer

Say it aloud. "A SavingsAccount **is an** Account" → inheritance. "A Car **has an** Engine" → composition.

Card 3process
Question

What does super() do?

Answer

Calls the **parent's** version — usually the constructor, which sets the inherited attributes. Without it those attributes are never set.

Card 4definition
Question

What is overriding?

Answer

A child class **redefining** a parent's method. Its version is used for objects of that class only.

Card 5concept
Question

Why is inheritance the tightest coupling in OOP?

Answer

A child depends on the parent's **internals**, not just its interface, so one change to the parent can break every subclass at once.

7.2.25 cards

Card 6definition
Question

What is polymorphism?

Answer

The **same call** behaving differently depending on the object it is made on — the caller never asks what type it holds.

Card 7comparison
Question

Overriding or overloading: same name, different parameters, one class?

Answer

**Overloading** — resolved at compile time. Overriding is a child replacing a parent's method, resolved at run time.

Card 8concept
Question

What does polymorphism replace?

Answer

A type-checking **if-chain**, repeated everywhere the objects are handled — and every copy is a place to forget a type.

Card 9example
Question

What does adding a new subclass cost in polymorphic code?

Answer

**Nothing** — it works with existing loops immediately, so no working code is edited and nothing can break.

Card 10concept
Question

Is inheritance the same as polymorphism?

Answer

No. Inheritance **shares** a method; polymorphism is the same call **resolving differently** per object. Inheritance is usually how it is achieved.

7.2.35 cards

Card 11definition
Question

What is abstraction?

Answer

Exposing only the operations a caller needs and **hiding how they are done**.

Card 12comparison
Question

Abstraction or encapsulation?

Answer

**Abstraction** decides *what* is exposed (design). **Encapsulation** enforces *how* it is protected (access control).

Card 13concept
Question

Why can an abstract class not be instantiated?

Answer

Its abstract methods have **no bodies**, so an object of it could be asked to run a method that does not exist.

Card 14comparison
Question

Abstract class or interface — when do you use each?

Answer

**Abstract class** when children share real behaviour and attributes. **Interface** when unrelated classes must offer the same operations.

Card 15example
Question

What is a leaky abstraction?

Answer

One where the caller must know **how** it works to use it correctly — saveToMySQL() rather than save().

7.2.45 cards

Card 16comparison
Question

Composition or aggregation — what is the difference?

Answer

Both are has-a. **Composition** owns the part, which dies with the whole. **Aggregation** references a part that exists independently.

Card 17process
Question

What is the survival test?

Answer

Delete the whole. If the part still makes sense it is **aggregation**; if it is meaningless it is **composition**.

Card 18example
Question

What is the tell in code?

Answer

The whole **creating** the part inside itself → composition. The part **passed in** → aggregation.

Card 19definition
Question

Which UML diamond means composition?

Answer

The **filled** diamond ◆. A hollow diamond ◇ means aggregation.

Card 20concept
Question

Why prefer composition over inheritance?

Answer

Looser coupling (interface, not internals), parts swappable at run time, and none of the parent's unwanted members.

7.2.55 cards

Card 21definition
Question

What is a design pattern?

Answer

A **named, reusable solution** to a recurring problem — a description of a structure and why it works, not a library.

Card 22definition
Question

What does the observer pattern do?

Answer

Objects **subscribe** to a subject and are notified when it changes. The subject never knows who is listening.

Card 23definition
Question

What is the factory pattern for?

Answer

Putting the decision of **which subclass to create** in one place, so concrete class names are not scattered through the code.

Card 24definition
Question

What is the strategy pattern?

Answer

Interchangeable algorithms behind one interface, **selected at run time** — replacing an if-chain that chooses behaviour.

Card 25concept
Question

Why is singleton criticised?

Answer

It is **global state**: testing becomes hard and the parts of the program that depend on it are hidden.

Want smart review reminders?

Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.

Start Free