CMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)Lecture 12:Runtime ManagementLast time:1.Parameter passing2.Libraries3.Public vs. privateToday:1.runtime stack management2.variable initialization3.function overloading rules4.thisCMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)1Call StackKeeps track of variablesStack FramesStack OperationspushpopEclipse can show the stackCMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)2Initialization of Variables SummaryLocal VariablesParametersInstance VariablesStatic VariablesCMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)3Overloading MethodsTwo methods with the same name but distinguishable parameter typesTerminology:prototype: public static void f(int x, float y)signature: f(int , float ) // names of variables and the return type are not part of itCan’t differ only in return typeCan’t differ only in types that can be implicitly promoted between (widening conversion) when choices are equal in amount of conversionCMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)4Implicit PromotionsOn general assignmentsOn parametersOn return valueCMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)5Most SUBTLE example:Consider overloading like this:void f(int x, double y)void f(double a, int b)Three Calls:f(3, 10.0) f(7.7, 5) f(3, 7)CMSC 131 Fall 2007Jan Plane (adapted from Bonnie Dorr)6thisa reference to the current object. (Only makes sense in a non-static method.)In an instance method, this is the object that is assumedeasy to refer to members (data or methods) using the assumed objectdifficult to refer to the whole object without having a name to call itOnly use when needed – using it all the time makes the code more difficult to
View Full Document