Notification System in Java: Explanation & Practice

Create notification type hierarchy

Problem summary

Create Notification interface with Email, SMS, Push implementations.

Starter code

// interface Notifiable: send(String message)
// EmailNotification: sends via email
// SMSNotification: sends via SMS
// PushNotification: sends via push

public class Main {
    public static void main(String[] args) {
        // Send notification via each channel
        // Print: [Type] Sent: <message>
    }
}

Expected output and test cases

  • Email notification
    [Email] Sent: Hello
  • SMS notification
    [SMS] Sent: Alert
  • Push notification
    [Push] Sent: Update

Hints

  1. Interface defines send() contract
  2. Each class formats output differently
  3. Use polymorphism to call correct send()

Related Inheritance exercises

Practice all Inheritance exercises · Run this idea in the Java compiler