Interfaces - in COBOL and Java

COBOL Java
*> Interface definition
interface-id IClock
01 Hour      binary-long property with no set.
01 Minute    binary-long property with no set.

method-id Reset.
end method.

end interface.

*> Extending an interface
interface-id IAlarmClock implements type IClock.
01 AlarmHour   binary-long property.
01 AlarmMinute binary-long property.

method-id Snooze (#time as binary-long).
end method.

end interface.

*> Interface implementation
class-id WristWatch implements type IAlarmClock,
                               type System.IDisposable.

working-storage section.
01 Hour        binary-long property with no set.
01 Minute      binary-long property with no set.
01 AlarmHour   binary-long property.
01 AlarmMinute binary-long property.
method-id Dispose.
    invoke self::Reset()
end method.

method-id Reset.
    set Hour to 0
    set Minute to 0
    set AlarmHour to 0
    set AlarmMinute to 0
end method.

method-id Snooze (#time as binary-long).
    add #time to AlarmMinute
end method.

end class.
// Interface definition
interface IClock
{
    int getHour();
    int getMinute();

    void reset();
}

// Extending an interface
interface IAlarmClock extends IClock
{
    int getAlarmHour();
    void setAlarmHour(int value);
    int getAlarmMinute();
    void setAlarmMinute(int value);

    void snooze(int time);
}

// Interface implementation
class WristWatch implements IAlarmClock, java.io.Closeable
{
    private int _hour, _minute, _alarmHour, _alarmMinute;

    public int getHour() { return _hour; }
    public int getMinute() { return _minute; }
    public int getAlarmHour() { return _alarmHour; }
    public void setAlarmHour(int value) { _alarmHour = value; }
    public int getAlarmMinute() { return _alarmMinute; }
    public void setAlarmMinute(int value) { _alarmMinute = value; }


    public void close()
    {
        reset();
    }

    public void reset()
    {        
        _hour = 0;
        _minute = 0;
        _alarmHour = 0;
        _alarmMinute = 0;
    }

    public void snooze(int time)
    {
        _alarmMinute += time;
    }
}

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.