Scope
Read the [Java program]. Pay particular attention to show(), its formal parameters, the calls of show(), and their actual parameters. Predict what the program does.
stack | objects | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
by new( ) | class (objects) | ||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||
|
|
After making your predictions, run the program and look at the output. Were your predictions correct?
main -- static
code0:... SuperClass.new() -- #1.new() SubClass.new() -- #2.new() ... show(#3, #4) -- i.e. code1 show(#4, #4) -- i.e. code1 ... return |
show(p0, p1) -- static
code1:... p0.method(p0) -- i.e. p0.class.method(p0) p0.method2(p0) -- i.e. p0.class.method2(p0) ... p1.method(p1) -- i.e. p1.class.method(p1) p1.method2(p1) -- i.e. p1.class.method2(p1) ... return |
method[p](this) -- in SuperClass
code2:... ... return |
method2(this) -- in SuperClass
code3:... ...memberVar... -- this.memberVar[p] ... method(this) -- ie this.class.method(this) ... return |
method[b](this) -- in SubClass
code4:... ... return |
(method2(this) -- ^above^,
|
-- LA 26/10/2004 |