Wednesday, July 27, 2011

Assignment 7 # 6

public class Test
{

private int x;
private static int y;
public void doIt()
{
x = 1;
y = 2;
}


public void tryIt() //cannot be static
{
x = 3; //x is in a static method - cannot be referenced
y = 4;
}
public static void main(String[] args)
{
doIt(); //object instance must be created
tryIt() //object instance must be created

Test t = new Test();
t.doIt();

Test.tryIt(); //must use t.tryIt();

}
}

No comments: