Escolar Documentos
Profissional Documentos
Cultura Documentos
c
VV VVV
ënow we can use ref_super ( reference variable of super class) to access the
methods of sub class, but we can access only redefine methods or inherited
methods.
If you assign a subclass reference to a super class reference, this ensures that
all components that can be accessed syntactically after the cast assignment are
actually available in the instance. The subclass always contain at least the same
components as the super class. After all, the name and the signature of redefined
methods are identical.
User can therefore address only those methods and attributes from the
subclass instance that they could from the super class instance,
So in the above example ref_super reference when call show method, it
actually access the implementation of show method from lcl_sub_class.
½
Down-cast (Narrowing Cast) Variables of the type reference to superclass
can also refer to subclass instances at runtime. You may now want to copy such a
reference (back) to a suitable variable of the type reference to subclass. If you want
to assign a superclass reference to a subclass reference, you must use the down-
cast assignment operator MOVE ... ?TO ... or its short form ?=. Otherwise, you
would get a message stating that it is not certain that all components that can be
accessed syntactically after the cast assignment are actually available in the
instance. As a rule, the subclass class contains more components than the
superclass. After assigning this type of reference (back) to a subclass reference to
the implementing class, clients are no longer limited to inherited components:
V
V
V
V
½
½
½