Just getting my feet wet with Java so I apologize if this seems a bit naive. I'm trying to get a better understanding of the conventions for accessing instance / member variables in practice.
Can a non-static instance variable be manipulated from a non-static context?
For instance, How could one modify the following class definition to allow the id and version variables to increment.
class Foo {
private int id;
private int version;
public String product;
public String model;
private Foo( ) {
// Can these variables be accessed from a non-static context?
id++;
version++;
}
...
In comparison with static fields ...
class Foo {
private static int id;
private static int version;
public String product;
public String model;
private Foo( ) {
id++;
version++;
}
...
First Example ...
1
1
Model One
First1
1
Model Two
Second
Second Example ...
1
1
Model One
First2
2
Model Two
Second