l A static method is one that is invoked through its class name, instead of through and object of that class. (page 199 Lewis, DePasquale, Chase)
l Variables can be static as well.
l Local variables are declared inside a method.
l Instance variables are declared in a class but not inside a method. The term is used because each instance of the class has its own version of the variable.
l A static variable sometimes called a class variable is shared among all instances of a class. There is only one copy of a static variable for all objects of the class. Therefore, changing the value of a static variable i one object changes it for all of the objects of that class.
I have been incorrectly using the
term class variable when I should
have been using the term instance variable or class field or class
attribute although these terms are not completely standardized.
l A static class member belongs to the class, not objects instantiated from the class
l An instance method performs an operation on a specific instance of the class.
l Static fields and static methods belong to the class instead of an instance of a class.
l
Look at the following code from our text: Countable.java
o Note
line 7: making
it private means that the variable cannot be accessed outside the class.
o Note
also: StaticDemo.java from
our text uses Countable.java