main() is a method. Any time we see a word with parens that means either a constructor or a method, but in flow control of a program it means "go somewhere and consider that list of instructions and come back to this point. In your example, i is an instance variable. To make i a member variable, you have to have an Object. Note in our class Bus, I use the default constructor -- it is not specifically spelled out, but the java compiler makes one... public Bus()
class Bus { // class names, by convention, are Cap
int i;
public static void main(String[] args) {
new Bus();
initThei( 99 );
// or
i = 10; // this is a member variable of bus
}
private void initThei( int value ) {
i = value;
}
}
static puts the expression on the heap...
static int, float, double, long, char... any primitive initializes to 0
static boolean initializes to false
static Object initializes to null
static has a value for free.
The confusion might lie with the fact that main() is a special method. The runtime looks for a main() to start the run. Only one main() is allowed. If a folder full of code has more than one main(), the others are ignored only the first one runs. Most of the time a class Object is separate from the main application.
class Bus {
int i;
public Bus() {
i = 10;
}
}
class MainApp {
Bus bus;
static void main(String[] args) {
bus = new Bus();
bus.i = 99; // changes the 10 into a 99
}
}