Java Programming Quiz 3 Static and nonStatic
Static class variables are not instance variables. The system allocates memory to hold class variables once per class, no matter how many instances of the class you instantiate. The system allocates memory for class variables the first time it encounters a class, and every instance of a class shares the same copy of any static class variables.
Instance fields and methods are nonstatic. The system allocates a separate memory location for each nonstatic field in each instance
Static fields in a class are called class fields
Nonstatic fields in a class are called instance variables.
Static methods in a class are called class methods.
Nonstatic methods in a class are called instance methods.
In Java, static is a keyword. It also can be used as an adjective.
There is no keyword for nonstatic items. When you do not explicitly declare a field or method to be static, then it is nonstatic by default.
When you create a class with a static field and instantiate 100 objects, only one copy of that field exists in memory.
When you create a class with a nonstatic field and instantiate 100 objects, then 100 copies of that field exist in memory
When you create a static method in a class and instantiate 100 objects, only one copy of the method exists in memory and the method does not receive a this reference.
When you create a nonstatic method in a class and instantiate 100 objects, only one copy of the method exists in memory, but the method receives a this reference that contains the address of the object currently using it
When you use a static field or method, you do not use an object; for example: JOptionPane.showDialog();
When you use a nonstatic field or method, you must use an object; for example: System.out.println();