CS 1114 Lecture Notes - Lecture 15: Null Pointer, Statics, Super Bowl Xxix
Document Summary
Upcoming assignments: complete program vi due m, 12/11 at 23:59. Notes: static fields or static variables belong to a class (a single copy is allocated). They are used for two purposes: efficiency one copy is enough because the value does not change and is often combined with. Final and sharing all objects must share the variable to ensure proper program semantics. Static fields are often used for declaring constants. They are initialized when a class is first used. Always initialize in the declaration, never inside of the constructor: example: public static final int max_size = 100, example: private static list treasures = new arraylist(); Static methods do not belong to a single object/instance, but rather to the class as a whole. They can be called from anywhere provided that access is allowed. They do not have a current object; they cannot access instance fields or call instance methods.