Notification

Report a typo

You have a class hierarchy of notifications. The parent class is Notification. It has two subclasses. Each subclass overrides a method.

class Notification {
    
    protected String msg;
    
    public Notification(String msg) {
        this.msg = msg;
    }
    
    public void show() {
        System.out.println(getMsg());
    }
    
    public String getMsg() {
        return msg;
    }
}

class Warning extends Notification {
    
    public Warning(String msg) {
        super(msg);
    }
    @Override
    public String getMsg() {
        return "WARN: " + msg;
    }
}

class Alarm extends Notification {
    
    public Alarm(String msg) {
        super(msg);
    }
    @Override
    public void show() {
        System.out.println("ALARM: " + msg);
    }
}

There are three objects:

Notification notif = new Notification("No problems");

Notification warn = new Warning("Money ends");
        
Notification alarm = new Alarm("The ship sank"); 

Select all correct statements about these objects.

Select one or more options from the list
___

Create a free account to access the full topic