Interactive Computer Science Tutoring

Learn programming concepts interactively

AHA Schools Logo

What Is an Interface?

Discover how interfaces create contracts that classes must fulfill

Understanding Interfaces

An interface is like a contract that defines what methods a class must implement. Think of it as the control panel of a device - it shows you what actions are possible, but each device can implement those actions differently!

Contract
Defines what must be done
Enforcement
Compiler ensures compliance
Flexibility
Each class implements differently
Interface Contract Status

Ready to Create Contract

Select an interface and create an implementation

Choose an Interface to Implement
Each interface represents a contract with different methods
Bicycle Interface Contract4 methods required
interface Bicycle {
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
Create Interface Implementation
Create a class that implements the Bicycle interface
Interface Contract Code
Live Java code showing interface contracts and implementations
// Interface Definition - The Contract
interface Bicycle {
// Contract: Must implement this method
void changeCadence(int newValue);
// Contract: Must implement this method
void changeGear(int newValue);
// Contract: Must implement this method
void speedUp(int increment);
// Contract: Must implement this method
void applyBrakes(int decrement);
}
Contract Activity0/5
Interface implementation progress

No operations yet

Start by adding or modifying elements