Equality, Interfaces, and Implementation Inheritance in Java

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/22

flashcard set

Earn XP

Description and Tags

Flashcards reviewing object-oriented programming concepts including equality design, hashing contracts, immutability, defensive copying, interfaces, subtyping, LSP, implementation inheritance, and composition.

Last updated 5:14 AM on 9/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

23 Terms

1
New cards

Identity Equality (==)

A reference comparison that checks whether two object reference variables point to the exact same object location in memory.

2
New cards

Value Equality (.equals())

A logical comparison that checks whether two separate object instances contain matching internal content or field values.

3
New cards

Four Steps of designing .equals()

The standard sequence for implementing value equality: 1) self-check (this == o), 2) null and class guard (o == null || getClass() != o.getClass()), 3) cast (Money other = (Money) o), and 4) field comparison.

4
New cards

equals / hashCode Contract

The fundamental Java rule stating that if a.equals(b) is true, then a.hashCode() == b.hashCode() must also be true.

<p>The fundamental Java rule stating that if a.equals(b) is true, then a.hashCode() == b.hashCode() must also be true.</p>
5
New cards

hashCode()

A method returning an integer hash value that determines which bucket or shelf an object goes into in hash-based collections before .equals() is used inside that bucket.

<p>A method returning an integer hash value that determines which bucket or shelf an object goes into in hash-based collections before .equals() is used inside that bucket.</p>
6
New cards

Immutability

A class design choice where object instances cannot be altered after creation, making them completely safe to share and alias across threads and data structures.

7
New cards

Copy-on-Change

A design pattern for immutable classes where state-modifying operations construct and return a brand-new object instance rather than mutating the existing one.

8
New cards

Defensive Copying

The practice of copying mutable objects when receiving them in constructors (copy IN) and when returning them in getter methods (copy OUT) to prevent internal state leaks.

9
New cards

Interface

A pure contract in Java that specifies method signatures declaring what an object can do, holding no instance state fields or method bodies.

10
New cards

implements

A Java keyword used by a class to declare that it fulfills an interface's contractual method signatures, enforced at compile time by javac.

11
New cards
<p>Static Type</p>

Static Type

The type of a variable as declared in source code and checked by the compiler at compile time.

12
New cards

Dynamic Type

The actual type of the object instance referenced on the heap at run time.

13
New cards

Subtyping (Substitutability)

The principle that an object of a subtype can stand in anywhere its supertype or interface type is expected.

14
New cards

Comparable

A Java interface declaring int compareTo(T o) used to define a class's single, natural internal ordering.

15
New cards

Comparator

A Java interface declaring int compare(T a, T b) used to define custom, external sort orderings without modifying the target class.

16
New cards

Liskov Substitution Principle (LSP)

The principle that a subtype must be substitutable for its supertype in behavioral contracts and promises, not merely in method signatures.

17
New cards

Implementation Inheritance (extends)

A Java mechanism allowing a subclass to inherit and reuse state fields and method implementations from a superclass.

18
New cards

protected

An access modifier that allows access to members within the declaring class itself, its package, and any derived subclasses.

<p>An access modifier that allows access to members within the declaring class itself, its package, and any derived subclasses.</p>
19
New cards

Constructor Chaining (super(…))

The mandatory execution of a superclass constructor at the beginning of a subclass constructor to initialize base layers first.

<p>The mandatory execution of a superclass constructor at the beginning of a subclass constructor to initialize base layers first.</p>
20
New cards

Method Overriding (@Override)

The practice of replacing a superclass method's implementation in a subclass using the exact same method signature, verified by the compiler via @Override.

21
New cards

Abstract Class

A class declared with the abstract keyword that contains a partial implementation (code and abstract method declarations) and cannot be directly instantiated.

22
New cards

Fragile Base Class Problem

An architectural flaw where unpromised internal changes in a superclass silently break the functionality of subclasses that relied on those internal implementation details.

23
New cards

Composition (HAS-A)

A design pattern where a class holds an instance of another object as a private field and delegates tasks to its public contract, avoiding the tight coupling of inheritance.