// Scoping.java
// Examples of block and class scope
import java.awt.*;
import javax.swing.*;

public class Scoping extends JApplet {
	int z = 50;  // instance variable
	int yPos = 25;  // just for printing purposes

	public void paint( Graphics g ) {
		int z = 10;  // local variable -- exists only in paint
		g.drawString( "local z in paint is " + z, 10, yPos );
		yPos += 20;

		alpha(g );  // alpha has its own local z
		beta( g );  // beta uses instance variable z
		alpha( g );  // alpha reinitializes its own z
		beta( g );  // beta still uses the instance variable -- since been modified

		g.drawString( "local z in paint is " + z, 10, yPos );
	}

	public void alpha( Graphics g ) {
		int z = 4;  // initialized to 4 each time alpha is invoked or called
		g.drawString( "local z in alpha after entering is " + z, 10, yPos );
		yPos += 20;
		z += 3;
		g.drawString( "local z in alpha before leaving is " + z, 10, yPos );
		yPos += 20;
	}

	public void beta( Graphics g ) {
		// does not have its own version of z
		// uses the instance variable
		g.drawString( "instance variable z in beta after entering is " + z, 10, yPos );
		yPos += 20;
		z += 3;  // modifies the instance variable
		g.drawString( "instance variable z in beta before leaving is " + z, 10, yPos );
		yPos += 20;
	}
}