Class variableName;
The syntactical difference is that an instance variable is not declared inside
of a method, it is just inside the class.
At this point, the actual code would make it clearer than just trying to discuss the proper syntax. So, let's start writing a class that represents a test score. A test score has two attributes tied to it - the number of points possible and the number of points earned.
Start of a TestScore Class
public class TestScore
{
private int pointsEarned;
private int pointsPossible;
}
Quick Review
|
Now, lets go over it. Here is the code again so you don't have to scroll up to see it.
TestScore Class (repeated)
public class TestScore
{
private int pointsEarned;
private int pointsPossible;
}