Exam Practice

MCQs, flashcards, UML scenario diagrams, and refactoring examples covering the four pillars, SOLID, GRASP, DRY/YAGNI/KISS, and code refactoring.

Reference text: Object First with Java, Barnes and Kölling, 6th Ed.

Each scenario below is described in plain English, followed by the UML class diagram rendered dynamically with Mermaid.js, supporting automatic theme switching (Light / Dark mode), proper multiplicity, and standard relationship notations.

Association

Student and Course

A Student can enroll in many Courses, and each Course can have many Students enrolled. Neither object owns the other, they simply know about each other.

Rendering UML diagram...
Aggregation

Team and Player

A Team has zero or more Players. A Player can exist on their own and can even move to a different team, so the Team does not own the Player's lifecycle.

Rendering UML diagram...
Composition

House and Room

A House is made up of one or more Rooms. A Room cannot exist on its own, if the House is destroyed, its Rooms are destroyed with it.

Rendering UML diagram...
Inheritance

Animal, Dog, and Cat

Dog and Cat are both kinds of Animal. Each subclass inherits the shared eat() behavior and may override it with its own version.

Rendering UML diagram...
Realization

Drawable, Circle, and Square

Circle and Square both promise to provide a draw() method, because they implement the Drawable interface. Each class supplies its own implementation.

Rendering UML diagram...
Dependency

OrderProcessor and PaymentGateway

OrderProcessor uses a PaymentGateway to process a single payment. It does not keep a permanent reference, so it only depends on PaymentGateway temporarily.

Rendering UML diagram...
Self-Association

Person and Manager

Each Person may have at most one manager. A manager, who is also a Person, may supervise zero or more employees.

Rendering UML diagram...
Inheritance + Realization

Duck, MallardDuck, RubberDuck, and Quackable

MallardDuck and RubberDuck both extend the abstract Duck class and inherit swim(). Only MallardDuck implements Quackable, since a rubber duck cannot really quack.

Rendering UML diagram...