![]() |
![]() |
![]() |
*> 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.
インターフェイスは、実装なしで名前およびシグネチャを指定するインスタンス メソッドのリストです。
プログラムで特定のインターフェイスの実装を宣言すると、そのインターフェイス内に定義されたすべてのメソッドの実装がプログラムで必要になります。インターフェイスを実装するには、クラス定義で OBJECT 句の IMPLEMENTS 指定を使用して、指定したインターフェイスの実装をプログラムが提供するように宣言します。また、このインターフェイス型へのオブジェクト参照も宣言できます。
Java インターフェイスには静的メソッドも含まれる場合があり、これらには他の静的メソッドと同様に直接アクセスできます。たとえば、インターフェイス MyInterface に文字列パラメーターを使用する静的メソッド Static1 が含まれている場合、次のようにコーディングできます。
invoke type MyInterface(“Hello”)
ただし、現在、COBOL インターフェイス内には静的メソッドを定義できません。