/** Upcasting, downcasting e instanceof. */
public class CastDemo {

    public static void main(String[] args) {
        Notification n = new SmsNotification("987654321", "Código 4821");  // upcasting implícito

        // n.phoneNumber() no compila: Notification no tiene ese método.
        if (n instanceof SmsNotification sms) {
            IO.println("Es un SMS para " + sms.phoneNumber());
        }

        Notification other = new EmailNotification("alice@example.com", "Hola");
        try {
            SmsNotification wrong = (SmsNotification) other;   // compila, pero...
            IO.println(wrong.phoneNumber());
        } catch (ClassCastException e) {
            IO.println("ClassCastException: " + e.getMessage());
        }
    }
}
