Lecture 17 10/24 see nonoop examples + Reminder from last lecture public class MC { classvariables; classmethods; } + Methods and variables can go in any order - For style, put vars first then methods - For methods, put approximately in order called + examples: nonoop1,2,3 + How to understand memory and access? -> SCOPE: portion of code from which variable/method can be accessed -> Use BOX DIAGRAMS -> boxes "carve" out portions of memory to store values -> represent both variables and methods with boxes -> boxes/values drawn/written at the location (space and time) a portion of code activates! + Scope (Box) Diagram rules (gradually updated as we introduce more language elements) . every class gets a box . every class variable gets a box inside the class box - default values of class variables are zeros what are zeros? $int$ has default of $0$ $double$ has default of $0.0$ $boolean$ has default of $false$ (and more to come) - every time a value changes, cross off the old value and write the new one to the right (or nearby) - every class method gets a box inside the class box WHEN the method is activated - write the method header above the method box . local variables - each local variable gets a box - local variables have unknown/undetermined values, so write a question mark (?) inside the local-variable box + Methods: each time the method activates, cross off the method box and draw a new one to the right ACTIVATION RECORD: the final collection is a record of the times the method was called + example: nonoop4 + see box diagram + why static? - no objects created yet class = blue print object = specific instance created using class as template - static means can use code DIRECTLY from class without making objects - generally, bad style: use only when have extremely common information - good style: information hiding - move information far away from user - security - reliability of code - ease of reuse