Java Reference
In-Depth Information
sum += val;
i++;
}
return sum;
}
7. Although the first release of Java didnot allow classes to nest, subsequent
releases did. This introducedproblems of nested access to objects, similar
to those found when subprograms are allowed to nest. Consider the
following Java class definition:
class Test {
class Local {
int b;
int v(){return a+b;}
Local(int val){b=val;}
}
int a = 456;
void m(){
Local temp = new Local(123);
int c = temp.v();
}
}
Note that method v() of class Local has access to field a of class Test
as well as field b of class Local. However, when temp.v() is called, it
is given a direct reference only to temp. Suggest a variant of static links
that can be used to implement nested classes so that access to all visible
objectsisprovided.
8. Consider the following C
/
C
++
structure declarations:
struct {int a; float b; int c[10];} s;
struct {int a; float b; } t[10];
Choose your favorite computer architecture. Show the code that would
be generated for s.c[5] assuming s is statically allocated at address
1000. What code would be generated for t[3].b if t is allocated within
aframeato
ff
set 200?
 
Search WWH ::




Custom Search