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.

Showing 101 cards
Class and Object

Object

termtap to reveal ↺
Definition

An instance of a class at a certain point in time, having state, behavior, and identity.

Objecttap to flip back ↺
Class and Object

Class

termtap to reveal ↺
Definition

A blueprint or template used to create objects, defining attributes and operations.

Classtap to flip back ↺
Class and Object

Attribute

termtap to reveal ↺
Definition

The state or data of an object, for example name and age for a Person.

Attributetap to flip back ↺
Class and Object

Operation / Method

termtap to reveal ↺
Definition

The behavior of an object, for example study() for a Student.

Operation / Methodtap to flip back ↺
Class and Object

Identity

termtap to reveal ↺
Definition

The property that distinguishes one object from another, even if their state is identical.

Identitytap to flip back ↺
Encapsulation

Encapsulation

termtap to reveal ↺
Definition

Combining data and operations together inside a boundary (usually a class) and protecting internal data from unnecessary outside access.

Encapsulationtap to flip back ↺
Encapsulation

Data hiding

termtap to reveal ↺
Definition

Restricting direct access to an object's fields, typically using private, so access is controlled through methods.

Data hidingtap to flip back ↺
Abstraction

Abstraction

termtap to reveal ↺
Definition

Showing important features while hiding unnecessary details, letting you focus on what an object does rather than how.

Abstractiontap to flip back ↺
Inheritance

Inheritance

termtap to reveal ↺
Definition

A mechanism allowing one class to acquire properties and behavior from another, creating an IS-A relationship.

Inheritancetap to flip back ↺
Inheritance

Superclass (Parent class)

termtap to reveal ↺
Definition

The more general class that other classes inherit from, for example Animal.

Superclass (Parent class)tap to flip back ↺
Inheritance

Subclass (Child class)

termtap to reveal ↺
Definition

The more specific class that inherits from a superclass, for example Dog extends Animal.

Subclass (Child class)tap to flip back ↺
Inheritance

Generalization

termtap to reveal ↺
Definition

The relationship pointing from a specific concept toward a more general one, for example Dog to Animal.

Generalizationtap to flip back ↺
Inheritance

Specialization

termtap to reveal ↺
Definition

The relationship pointing from a general concept toward a more specific one, for example Animal to Dog.

Specializationtap to flip back ↺
Abstract Class and Interface

Abstract class

termtap to reveal ↺
Definition

A class that cannot be instantiated directly. It may contain abstract methods that subclasses must implement.

Abstract classtap to flip back ↺
Abstract Class and Interface

Abstract method

termtap to reveal ↺
Definition

A method declared without a body inside an abstract class, requiring a concrete subclass to provide the implementation.

Abstract methodtap to flip back ↺
Abstract Class and Interface

Interface

termtap to reveal ↺
Definition

A specification or contract describing what a class must be able to do, defined using the interface keyword.

Interfacetap to flip back ↺
Abstract Class and Interface

Concrete class

termtap to reveal ↺
Definition

A class that can be instantiated directly because all of its methods are fully implemented.

Concrete classtap to flip back ↺
Polymorphism

Polymorphism

termtap to reveal ↺
Definition

The ability of one thing to take many forms; a variable can refer to objects of different types.

Polymorphismtap to flip back ↺
Polymorphism

Polymorphic variable

termtap to reveal ↺
Definition

A variable whose declared (supertype) type can hold objects of different subtypes at different times.

Polymorphic variabletap to flip back ↺
Polymorphism

Method overriding

termtap to reveal ↺
Definition

When a subclass provides a different implementation of a method inherited from its superclass, using the same signature.

Method overridingtap to flip back ↺
Polymorphism

Method overloading

termtap to reveal ↺
Definition

Defining multiple methods with the same name but different parameter lists, resolved at compile time.

Method overloadingtap to flip back ↺
Polymorphism

Dynamic method dispatch

termtap to reveal ↺
Definition

The process by which Java decides which overridden method to execute based on the actual object type at runtime.

Dynamic method dispatchtap to flip back ↺
Polymorphism

Compile-time type

termtap to reveal ↺
Definition

The declared type of a variable, for example Animal in Animal animal = new Dog();.

Compile-time typetap to flip back ↺
Polymorphism

Runtime object (actual type)

termtap to reveal ↺
Definition

The real type of the object a variable refers to at execution time, for example Dog in Animal animal = new Dog();.

Runtime object (actual type)tap to flip back ↺
UML Relationships

Association

termtap to reveal ↺
Definition

A relationship representing that objects are connected and can interact, for example Student and Course.

Associationtap to flip back ↺
UML Relationships

Multiplicity

termtap to reveal ↺
Definition

A UML notation describing how many objects can participate in a relationship, such as 1, 0..1, *, 0..*, 1..*.

Multiplicitytap to flip back ↺
UML Relationships

Aggregation

termtap to reveal ↺
Definition

A whole-part relationship with weak ownership; the part can exist independently of the whole. Shown with a hollow diamond.

Aggregationtap to flip back ↺
UML Relationships

Composition

termtap to reveal ↺
Definition

A whole-part relationship with strong ownership; the part's lifecycle depends on the whole. Shown with a filled diamond.

Compositiontap to flip back ↺
UML Relationships

Dependency

termtap to reveal ↺
Definition

A relationship where one class uses another; changes in the used class may affect the dependent class.

Dependencytap to flip back ↺
UML Relationships

Realization

termtap to reveal ↺
Definition

A relationship where a class implements an interface, usually shown as a dashed arrow toward the interface.

Realizationtap to flip back ↺
Cohesion and Coupling

Cohesion

termtap to reveal ↺
Definition

How closely related the responsibilities inside a class are. Higher cohesion is generally better.

Cohesiontap to flip back ↺
Cohesion and Coupling

Coupling

termtap to reveal ↺
Definition

The level of dependency between objects or classes. Lower coupling is generally better.

Couplingtap to flip back ↺
Cohesion and Coupling

High cohesion + low coupling

termtap to reveal ↺
Definition

The combination good OO design generally aims for, leading to code that is easier to understand, maintain, and modify.

High cohesion + low couplingtap to flip back ↺
UML Diagrams

UML class diagram

termtap to reveal ↺
Definition

A visual box divided into class name, attributes, and operations, representing a class and its structure.

UML class diagramtap to flip back ↺
UML Diagrams

Visibility symbol +

termtap to reveal ↺
Definition

Denotes public visibility in a UML class diagram.

Visibility symbol +tap to flip back ↺
UML Diagrams

Visibility symbol -

termtap to reveal ↺
Definition

Denotes private visibility in a UML class diagram.

Visibility symbol -tap to flip back ↺
UML Diagrams

Visibility symbol #

termtap to reveal ↺
Definition

Denotes protected visibility in a UML class diagram.

Visibility symbol #tap to flip back ↺
SOLID Principles

SOLID

termtap to reveal ↺
Definition

An acronym for five OO design principles: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.

SOLIDtap to flip back ↺
SOLID Principles

Single Responsibility Principle (SRP)

termtap to reveal ↺
Definition

A class should have one main responsibility, one reason to change.

Single Responsibility Principle (SRP)tap to flip back ↺
SOLID Principles

Open-Closed Principle (OCP)

termtap to reveal ↺
Definition

Software entities should be open for extension but closed for modification.

Open-Closed Principle (OCP)tap to flip back ↺
SOLID Principles

Liskov Substitution Principle (LSP)

termtap to reveal ↺
Definition

A subtype object should be usable wherever its supertype object is expected, without breaking correctness.

Liskov Substitution Principle (LSP)tap to flip back ↺
SOLID Principles

Interface Segregation Principle (ISP)

termtap to reveal ↺
Definition

A class should not be forced to depend on methods it does not need; prefer several small interfaces.

Interface Segregation Principle (ISP)tap to flip back ↺
SOLID Principles

Dependency Inversion Principle (DIP)

termtap to reveal ↺
Definition

High-level and low-level components should both depend on abstractions, not on each other's concrete details.

Dependency Inversion Principle (DIP)tap to flip back ↺
Java Keywords

class

termtap to reveal ↺
Definition

Defines a class, the blueprint for creating objects.

classtap to flip back ↺
Java Keywords

new

termtap to reveal ↺
Definition

Creates a new object instance.

newtap to flip back ↺
Java Keywords

extends

termtap to reveal ↺
Definition

Used to inherit from a superclass.

extendstap to flip back ↺
Java Keywords

implements

termtap to reveal ↺
Definition

Used when a class provides the behavior required by an interface.

implementstap to flip back ↺
Java Keywords

abstract

termtap to reveal ↺
Definition

Marks a class or method as incomplete or too general to instantiate directly.

abstracttap to flip back ↺
Java Keywords

interface

termtap to reveal ↺
Definition

Defines a contract of required behavior that implementing classes must provide.

interfacetap to flip back ↺
Java Keywords

private

termtap to reveal ↺
Definition

Restricts a member's access to inside its own class only.

privatetap to flip back ↺
Java Keywords

public

termtap to reveal ↺
Definition

Allows a member to be accessed from any other class.

publictap to flip back ↺
Java Keywords

@Override

termtap to reveal ↺
Definition

Marks that a method is intentionally overriding a superclass method.

@Overridetap to flip back ↺
Code Refactoring

Code Refactoring

termtap to reveal ↺
Definition

Restructuring existing code to improve its internal design, without changing its external behavior.

Code Refactoringtap to flip back ↺
Code Refactoring

Technical Debt

termtap to reveal ↺
Definition

Problems caused by quick, messy, or poor coding decisions that make future changes harder.

Technical Debttap to flip back ↺
Code Refactoring

Code Smell

termtap to reveal ↺
Definition

A sign that code may have a deeper design problem. It does not always mean the code is broken.

Code Smelltap to flip back ↺
Code Refactoring

Legacy Code

termtap to reveal ↺
Definition

Existing code inherited from another developer or older system, often hard to understand and undertested.

Legacy Codetap to flip back ↺
Code Refactoring

Extract Method

termtap to reveal ↺
Definition

Move a block of related code out of a long method into a new, well-named method.

Extract Methodtap to flip back ↺
Code Refactoring

Inline Method

termtap to reveal ↺
Definition

Remove an unnecessary method and place its code directly where it was called.

Inline Methodtap to flip back ↺
Code Refactoring

Extract Class

termtap to reveal ↺
Definition

Split an overloaded class's responsibilities by moving related fields and methods into a new class.

Extract Classtap to flip back ↺
Code Refactoring

Inline Class

termtap to reveal ↺
Definition

Merge a nearly useless class's features into another class and remove it.

Inline Classtap to flip back ↺
Code Refactoring

Move Method

termtap to reveal ↺
Definition

Relocate a method to the class it uses most, since that is where it truly belongs.

Move Methodtap to flip back ↺
Code Refactoring

Move Field

termtap to reveal ↺
Definition

Relocate a field to the class that uses it most.

Move Fieldtap to flip back ↺
Code Refactoring

Replace Temp with Query

termtap to reveal ↺
Definition

Replace a temporary variable that stores an expression's result with a method call.

Replace Temp with Querytap to flip back ↺
Code Refactoring

Rename Variable / Method

termtap to reveal ↺
Definition

Rename an unclear identifier to a meaningful name so the code explains itself.

Rename Variable / Methodtap to flip back ↺
Code Refactoring

Pull Up Field

termtap to reveal ↺
Definition

Move a field shared by multiple subclasses up into their common superclass.

Pull Up Fieldtap to flip back ↺
Code Refactoring

Push Down Field

termtap to reveal ↺
Definition

Move a field that only some subclasses need down into just those subclasses.

Push Down Fieldtap to flip back ↺
Code Refactoring

Pull Up Method

termtap to reveal ↺
Definition

Move a duplicate method shared by subclasses up into the superclass.

Pull Up Methodtap to flip back ↺
Code Refactoring

Push Down Method

termtap to reveal ↺
Definition

Move a method that only some subclasses need down into just those subclasses.

Push Down Methodtap to flip back ↺
Code Refactoring

Extract Interface

termtap to reveal ↺
Definition

Create an interface containing a common subset of methods that several clients need.

Extract Interfacetap to flip back ↺
Code Refactoring

Replace Type Code with Subclasses

termtap to reveal ↺
Definition

Replace an if/switch on a type code with a proper subclass hierarchy.

Replace Type Code with Subclassestap to flip back ↺
Code Refactoring

Decompose Conditional

termtap to reveal ↺
Definition

Extract a complex condition and its branches into small, clearly named methods.

Decompose Conditionaltap to flip back ↺
Code Refactoring

Introduce Parameter Object

termtap to reveal ↺
Definition

Replace many related method parameters with a single object that groups them.

Introduce Parameter Objecttap to flip back ↺
Code Refactoring

Replace Conditional with Polymorphism

termtap to reveal ↺
Definition

Replace type-checking switch/if logic with overridden methods on each subclass.

Replace Conditional with Polymorphismtap to flip back ↺
Code Refactoring

Substitute Algorithm

termtap to reveal ↺
Definition

Replace an existing algorithm with a simpler or cleaner one that produces the same result.

Substitute Algorithmtap to flip back ↺
GRASP / DRY / YAGNI / KISS

DRY (Don't Repeat Yourself)

termtap to reveal ↺
Definition

Every piece of knowledge or logic should have a single, authoritative representation, avoid duplicating it.

DRY (Don't Repeat Yourself)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

YAGNI (You Aren't Gonna Need It)

termtap to reveal ↺
Definition

Don't build functionality until it is actually needed, avoid speculative features.

YAGNI (You Aren't Gonna Need It)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

KISS (Keep It Simple, Stupid)

termtap to reveal ↺
Definition

Prefer the simplest solution or design that correctly solves the problem.

KISS (Keep It Simple, Stupid)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Hollywood Principle

termtap to reveal ↺
Definition

"Don't call us, we'll call you", an inversion of control where a framework or superclass calls into your code.

Hollywood Principletap to flip back ↺
GRASP / DRY / YAGNI / KISS

GRASP

termtap to reveal ↺
Definition

General Responsibility Assignment Software Patterns, a set of principles for deciding which class should have which responsibility.

GRASPtap to flip back ↺
GRASP / DRY / YAGNI / KISS

Information Expert (GRASP)

termtap to reveal ↺
Definition

Assign a responsibility to the class that already has the information needed to fulfill it.

Information Expert (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Creator (GRASP)

termtap to reveal ↺
Definition

Assign creation of B to class A when A aggregates, contains, or closely uses B.

Creator (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Controller (GRASP)

termtap to reveal ↺
Definition

Assign handling of a system event to a dedicated non-UI class representing the use case or system.

Controller (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Low Coupling (GRASP)

termtap to reveal ↺
Definition

Assign responsibilities so dependencies between classes stay minimal.

Low Coupling (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

High Cohesion (GRASP)

termtap to reveal ↺
Definition

Assign responsibilities so a class's tasks stay closely related and focused.

High Cohesion (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Polymorphism (GRASP)

termtap to reveal ↺
Definition

Assign behavior that varies by type to the types themselves via overriding, instead of conditionals.

Polymorphism (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Pure Fabrication (GRASP)

termtap to reveal ↺
Definition

Create an artificial class outside the problem domain purely to achieve low coupling and high cohesion.

Pure Fabrication (GRASP)tap to flip back ↺
GRASP / DRY / YAGNI / KISS

Protected Variations (GRASP)

termtap to reveal ↺
Definition

Shield elements from variation elsewhere by wrapping the unstable point behind a stable interface.

Protected Variations (GRASP)tap to flip back ↺
Additional Topics

Constructor

termtap to reveal ↺
Definition

A special method used to initialize a new object's state; shares the class name and has no return type.

Constructortap to flip back ↺
Additional Topics

Default constructor

termtap to reveal ↺
Definition

The no-argument constructor Java automatically provides when a class defines no constructor of its own.

Default constructortap to flip back ↺
Additional Topics

this keyword

termtap to reveal ↺
Definition

A reference to the current object instance, often used to disambiguate fields from parameters.

this keywordtap to flip back ↺
Additional Topics

super keyword

termtap to reveal ↺
Definition

A reference used to call a superclass's constructor or an overridden superclass method.

super keywordtap to flip back ↺
Additional Topics

static member

termtap to reveal ↺
Definition

A field or method that belongs to the class itself and is shared across all instances, rather than belonging to one object.

static membertap to flip back ↺
Additional Topics

protected access

termtap to reveal ↺
Definition

A visibility level accessible within the same package and by subclasses in other packages.

protected accesstap to flip back ↺
Additional Topics

default (package-private) access

termtap to reveal ↺
Definition

A visibility level, with no modifier written, accessible only to classes in the same package.

default (package-private) accesstap to flip back ↺
Additional Topics

equals() and hashCode()

termtap to reveal ↺
Definition

Methods that define logical equality between objects; they should be overridden together so hash-based collections behave correctly.

equals() and hashCode()tap to flip back ↺
Additional Topics

toString()

termtap to reveal ↺
Definition

A method returning a human-readable string representation of an object, commonly overridden for debugging or display.

toString()tap to flip back ↺
Additional Topics

Immutability

termtap to reveal ↺
Definition

A property of an object whose state cannot change after construction, making it easier to reason about and share safely.

Immutabilitytap to flip back ↺
Additional Topics

Information hiding

termtap to reveal ↺
Definition

The general design principle of hiding implementation details from clients; encapsulation is the language mechanism used to achieve it.

Information hidingtap to flip back ↺
Additional Topics

Factory pattern

termtap to reveal ↺
Definition

A design pattern that encapsulates and centralizes object creation logic, decoupling clients from concrete constructors.

Factory patterntap to flip back ↺
Additional Topics

Generics

termtap to reveal ↺
Definition

A Java feature providing type safety and reusable code that works across different types, checked at compile time.

Genericstap to flip back ↺
Additional Topics

Method signature

termtap to reveal ↺
Definition

A method's name together with its parameter types; it does not include the return type.

Method signaturetap to flip back ↺