Mais inner classes: exemplo de escopo de uma Local Class

class A { protected char a = ‘a’; }
class B { protected char b = ‘b’; }
public class C extends A
{
private char c = ‘c’; // Private fields visible to local class.
public static char d = ‘d’;
public void createLocalObject(final char e)
{
final char f = ‘f’;
int i = 0; // i not final; not usable by local class.
class Local extends B
{
char g = ‘g’;
public void printVars()
{
// All of these fields and variables are accessible to this class.
System.out.println(g); // (this.g) g is a field of this class.
System.out.println(f); // f is a final local variable.
System.out.println(e); // e is a final local argument.
System.out.println(d); // (C.this.d) d – field of containing class.
System.out.println©; // (C.this.c) c – field of containing class.
System.out.println(b); // b is inherited by this class.
System.out.println(a); // a is inherited by the containing class.
}
}
Local l = this.new Local(); // Create an instance of the local class
l.printVars(); // and call its printVars() method.
}

public static void main(String[] args)
{
// Create an instance of the containing class, and invoke the
// method that defines and creates the local class.
C c = new C();
c.createLocalObject(‘e’); // pass a value for final parameter e.
}
}

Cara,

Desse jeito tu vai gabaritar a prova da Sun…

heheehehe… tipo… as questões estão bem massa… mas vê se consegue aninhar elas pra facilitar a visualização e tenta usar o code

Gustavo Guilherme BacK