1/14
What does an abstraction focus on?
What behavior is available
What can a client rely on
What must remain stable
What does abstraction hide?
What data structure is used
Which algorithm is used
Which service does the work
What can an abstract class contain?
Instance fields
Constructors
Concrete methods
Abstract methods
Private/protected helpers
What can an abstract class cannot contain/do?
Cannot be instantiated directly with new (cannot make objects)
A concrete subclass must finish the missing pieces
When should an abstract class be used?
Used when related implementation truly share code, state, invariants, or an algorithm skeleton
Extends vs implements
A class extends at most one class
A class can implement many interfaces
An interface can extend another interface
Every runtime object is still a concrete class
What is the common pattern for interfaces and abstract classes?
Interfaces for the public role
Abstract class for shared code
Concrete subclasses for the representation-specific details
Implements make a _____
promise
Extends inherits ______
From a parent type
Primary methods
core capability that depends on implementation details. Often abstract in an interface
Secondary methods
Behavior built from existing public operations. Often a default method
Declared type
Type of a variable from its declaration. Compile time: Which methods can be called
Dynamic type
Class of the reference object. Runtime: Which instance-method implementation runs?
What does the declared type determine?
Determines which methods can be called
What does the dynamic type determine?
Determines how the method runs