The example:
/*filename:TestScope.java */
import java.awt.*;
import java.applet.Applet;
class TestScope extends Applet
{
static int x = 1;
public void paint( Graphics g )
{
int x = 0;
g.drawString("x=" + x,30, 30);
g.drawString("TestScope.x=" + Test.x,30, 50);
}
}
<!--filename:TestScope.html-->
<applet code="TestScope.class" width=180 height=60>
</applet>
produces the output:
x=0 TestScope.x=1
This example declares:
- a class
TestScope
which is a subclass of Applet
- a class (
static
) variable x
that is a member of the class TestScope
- a class method
paint
that is a member of the class TestScope
- a parameter
g
of the paint
method
- a local variable
x
of the paint
method