*T'Nora Green
*Assignment 7, Exercise 6
*************************************/
public class Test
{
private int x;
private static int y;
public void doIt()
{
x = 1;
y = 2;
}
public static void tryIt()
{
x = 3;
y = 4;
}
public static void main(String[] args)
{
doIt();
tryIt();
Test t = new Test();
t.doIt();
Test.doIt();
Test.tryIt();
}
} // end Test class
Reasons for errors from the debugger:
non-static variable x cannot be referenced from the static tryIt method
non-static method doIt() cannot be referenced from the static main method
non-static method doIt cannot be referenced instance method using a dot prefix.
/************************************
*T'Nora Green
*Assignment 7, Exercise 10
*T'Nora Green
*Assignment 7, Exercise 10
*************************************/
Yes, its legal to omit the PennyJar dot prefixes in the PennyJar class. In the PennyJarDriver class PennyJar.getAllPennies() is needed and cannot be omitted.
No comments:
Post a Comment