Interfaces and Abstract Classes
Learn two important Java tools for designing reusable and structured applications.
Java Code
Study the example and understand what each part does.
interface Payment {
void pay();
}
class MpesaPayment implements Payment {
public void pay() {
System.out.println("Payment completed");
}
}
public class Main {
public static void main(String[] args) {
Payment payment = new MpesaPayment();
payment.pay();
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Payment completed
Finished this lesson?
Mark it complete to update your course progress.