Summary of Class Presentation for June 15, 1999 We started by looking at some examples of writing equals methods for user developed classes. In general, an equals method would take a single parameter, an object of the same class. Then the equals method would contain a single return statement that would do ands (&&) of comparisons between corresponding data fields in the current object and the parameter object. These comparisons would use == if the data field was a primitive type ( byte, short, int, long, float, double, char, or boolean) and call the equals method for the corresponding class, if the data field was itself an object. If the data field was an array, a loop should be used to compare corresponding elements in each array. Of course, if the loop was needed, we could not write the equals method as a single return statement. Instead, we would need a boolean variable to maintain the result of the comparisons as we executed a loop to do them. This boolean variable would then be used in the return statement. We looked at Java flow of control. Java control constructs are basically the same as those in C and C++: if, while, do-while, and switch. There are two major differences, however: 1. A new Java variable can be declared in any block including in the header for a for loop, but the name of that variable cannot match that of any other variable that is active at that point; 2. Java supports the use of labels in continue and break statements to allow branches out of nested loops to the outer loop headers. A label is a name followed by a colon. Labels may be placed only on the headers of loops ( while, for, do-while). A continue or break statement then can specify the label, for example break outj; where outj is a label. Control would then jump to that header statement just like when the bottom of that outer loop is reached during normal execution. For a break, execution would proceed with the statement following the labeled loop. For a continue, execution would proceed with the next iteration of the labeled loop.