Scope

home1 home2
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 Book

ProgLang
 glossary
 Java
  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)
 
^
|
show
superObj
subObj
---> ?
--->#4
main
superObj
subObj
--->#3
--->#4
 
 
#0:
Test
main( )
show( )
 
--->code0
--->code1

#3:
superObj
class=SuperClass
memberVar=...
 
--->#1
 
 
#1:
SuperClass
Super
staticVar=...
method( )
method2( )
 
--->Object
 
--->code2
--->code3

#4:
subObj
class=SubClass
memberVar=...
(shadowed!)
memberVar=...
 
--->#2
 
 
 
#2:
SubClass
Super
staticVar=...
method( )
(overrides)
method2( )
--->#1
 
--->code4
 
--->code3

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^, inherited by SubClass)
-- LA 26/10/2004
Coding Ockham's Razor, L. Allison, Springer

A Practical Introduction to Denotational Semantics, L. Allison, CUP

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite
The GIMP
~ free photoshop
Firefox
web browser

Java
 API

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 29-Mar-2024 06:31:29 AEDT.