|
|
||||||
|
|||||||||||||||
|
|
|||||||||||||||
2.5 staticUNDER CONSTRUCTION: THIS SECTION IS NOT YET COMPLETEExample:
Static: class variables/methods Non-static: instance (object) variables/methods Static variables and methods are associated with the class! Instance variables/methods are associated with a particular instantiated object Static - Can be called directly using the class name! For example:
All objects instantiated from the class share its static variables Changing the value of a static variable in one object changes it for all others!!! cannot reference instance variables (because instance variables don't exist until an object exists) can reference static class variables or its own local variables main() is static – it gets invoked before any class is instantiated Example: Let’s make our Person class know how many Person objects were instantiated
|
|||||||||||||||