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.
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.
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.
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.
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.
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.
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.
Person and Manager
Each Person may have at most one manager. A manager, who is also a Person, may supervise zero or more employees.
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.