Professional Documents
Culture Documents
• Feature 1: Inheritance
• Feature 2: Method overriding
• Feature 3: Polymorphism
• Feature 4: Dynamic binding
• Feature 5: Multiple inheritance
• Feature 6: Dependent multiple inheritance
Feature 1: Inheritance
• Inheritance, present in all object-oriented languages,
allows the programmer to base a class B on a class A,
so that B inherits the methods and fields of A, in
addition to its own fields and methods.
• This feature is also known as type extension: class B
extends class A with zero or more fields and
methods.
• Class A is the parent class of class B, and class B is a
subclass of class A. Now suppose that class B extends
class A by adding a method m3 and a field b1.
• The run-time representation of an object of
class B is then:
main() Act.
record for
Control link main
P
Fun()
Control link Dangling
reference
11.3.3 Routines
• A routine is just a piece of code, reachable through a
pointer to its first instruction, its code address.
• When a routine R is called (invoked, activated) an
activation record is created for it and the flow of control is
transferred to its first instruction by setting the program
counter to the routine code address; the routine is now
running.
• Routines that are running or suspended have activation
records; they are called active.
• A routine can be active more than once simultaneously, in
which case it is recursive; only one invocation can be
running at any given time.
• When a routine returns, its activation record is removed.
When the last activation record of a routine has been
removed, the routine becomes inactive again.
11.3.4 Operations on routines
• Operations on routines include declaring a routine
(specifying its name, parameter types, and return
type),
• Defining a routine (declaring it and supplying its code),
• The most important operation on a defined routine is
calling it.
• Once a defined routine is seen as a value, two more
operations on it become possible: passing it as a
parameter to a routine in a call, and returning it as a
value from a routine call.
• A less frequent operation is jumping out of a routine.
The destination of such a jump, also called a non-local
goto, is a non-local label.
• A non-local label is a
label in another
routine.
• The routine level_2()
contains a non-local
goto statement to
label L_1 in routine
level_1().
11.3.5 Non-nested routines
• A non-nested routine is represented at run time
simply by the start address of its code.
• A non-nested running routine has access to two
environments only: the global data area and its
own activation record.
• The global data area is addressed directly.
• The routine’s own activation record is accessible
through the frame pointer FP.
• A non-nested routine can be passed on as a
parameter or returned as a value by just passing
on or returning its code address.
11.3.6 Nested routines
• A nested routine can access global entities and its own
local entities, and can in addition access entities in
lexically intervening routines.
• Nested routines require access to lexically intervening
routines.
• This can be implemented by means of a lexical
pointer, which is a copy of the frame pointer of the
lexically enclosing scope.
• Passing a nested routine as a parameter or returning it
as a result requires a two pointer value: a lexical
pointer and a routine address.
• Returning a nested routine as a result may violate
pointer scope rules.
11.4 Code generation for control flow
statements
• Three levels of flow of control can be distinguished:
• local flow of control, which determines the statement
inside a routine or method to be executed next
(Section 11.4.1);
• routine calls and method invocations, which perform
the parameter transfer and flow-of-control
manipulation needed to activate a new routine
(Section 11.4.2);
• non-local jumps, which transfer the flow of control out
of the currently running routine into an ancestor
routine (Section 11.4.2.3).
11.4.1 Local flow of control