LECTURE NOTES SEPTEMBER 27 2004 ASSIGNMENTS 10/1 Assignment 1 - Be sure to read style and commenting guides online: you will be graded on these! CodeLab 4 USING VISIBILITY MODIFIERS Why? - ensure class integrity - avoid back doors that can break the functionality of the class What? - private data members How? - clients can only access data in ways you specifically enable What? - public class constants Why? - by nature can't be modified - clean way to make certain characteristics of instances known to client programmers What? - using public class data members How? - . What? - visibility modifiers and class diagrams how? - place symbol at beginning of each data member or method - "+" for public - "-" for private VARIABLE SCOPE: USING ARGUMENTS, PARAMETERS, AND LOCAL VARIABLES What? - using data members within a class definition How? - refer to them by name What? - declaring *local variables* Why? - temporary purposes - storing the intermediate result of a computation What? - parameter - variable input to a method - optional What? - accessibility of local variables and parameters When? - within the method in which they are declared - available only when the method is being executed What? - memory usage of local variables and parameters How? - memory space - allocated at the beginning of the method - erased upon exiting from the method What? - passing arguments to a method When? - a method is called How? - value of argument stored in the parameter in the corresponding position - *pass-by-value* / call-by-value - parameter and argument names can be the same Ramifications? - changes made to the parameter do not affect the original argument - data type of argument must be assignment-compatible with the data type of the parameter Program Diagram Notation? () What? - returning values from a method How? - data type of the return value must be assignment-compatible with the declared return type - method call acts like an expression that evaluates to the method's return value Ramifications? - *method composition* Program Diagram Notation? () : What? - passing objects How? - pass by value - data just happens to be the address of an object Ramifications? - object itself is shared, not copied What? - returning objects How? - make the return type the name of a class Ramifications? - method call evaluates to the address of the returned object What? - pass-by-reference: the address of a variable is passed as a parameter - aka call-by-reference How? - not done in Java