This program will show simple use of an interface with its own data and methods and how it is implemented in a class. It will also show that there can be methods of same name for an interface and the class implementing the interface.
-------------------------------------------------------------------------------------------
report ysubdel .
interface i1.
data : num type i .
methods : meth1.
endinterface.
class c1 definition.
public section.
methods : meth1. “ class C1’s own method
interfaces : i1.
endclass.
class c1 implementation.
method : meth1.
write:/5 'I am meth1 in c1'.
endmethod.
method i1~meth1.
write:/5 'I am meth1 from i1'.
endmethod.
endclass.
start-of-selection.
data : oref type ref to c1.
create object oref.
write:/5 oref->i1~num.
call method oref->meth1.
call method oref->i1~meth1.
Output:
0
I am meth1 in c1
I am meth1 from i1
No comments:
Post a Comment