CS 1114 Lecture Notes - Lecture 15: Null Pointer, Statics, Super Bowl Xxix

78 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents