FileDocCategorySizeDatePackage
AClass.javaAPI DocExample1258Tue Dec 12 18:58:16 GMT 2000None

AClass

public class AClass extends Object

Fields Summary
public int
instanceInteger
public static int
classInteger
Constructors Summary
Methods Summary
public static intclassMethod()

        
        return classInteger;
    
public intinstanceMethod()

       
        return instanceInteger;
    
public static voidmain(java.lang.String[] args)

        AClass anInstance = new AClass();
        AClass anotherInstance = new AClass();

        //Refer to instance members through an instance.
        anInstance.instanceInteger = 1;
        anotherInstance.instanceInteger = 2;
        System.out.println(anInstance.instanceMethod());
        System.out.println(anotherInstance.instanceMethod());

        //Illegal to refer directly to instance members from a class method
        //System.out.println(instanceMethod());    //illegal
        //System.out.println(instanceInteger);     //illegal

        //Refer to class members through the class...
        AClass.classInteger = 7;
        System.out.println(classMethod());

        //...or through an instance.
        System.out.println(anInstance.classMethod());

	//Instances share class variables
        anInstance.classInteger = 9;
        System.out.println(anInstance.classMethod());
        System.out.println(anotherInstance.classMethod());