CS100J, Spring 2001 Thurs 2/15 Lecture 8 ------------------------------------------------------------------------------- Announcements: + I was out sick 2/8 (after lecture) - Mon 2/19 (afternoon) ------------------------------------------------------------------------------- Topics: + removing redundancy with methods (think functions) + designing methods in main class + issues: returning value, not returning value, passing by value, scope ------------------------------------------------------------------------------- Summary from Lecture 7 + functions that return value + methods as functions ------------------------------------------------------------------------------- What you should have learned at this point: + rudiments of object oriented programming using the main class + make variables and methods $static$ public class mainclassname { // put static variables here: static int x; static double y; // variables declared at the "class level" // are visible throughout the class // advantage: methods can share variables and their values // put static methods here: public static void main(String[] args) { // statements } public static returntype methodname(arguments) { // statements } public static returntype methodname(arguments) { // statements } // all the methods can call eachother ------------------------------------------------------------------------------- Scope: + what portion of the code is visible to another portion + think visibility -- can a portion of code see a particular variable? method? class? + look for braces { } stuff inside the { } can only see methods and variables written inside the braces + for classes, you will see that classes can be used from other classes when the classes are located in the same project -------------------------------------------------------------------------------