lec7 - Page 1 of 31 CSE 8A, UCSD LEC7 CSE 8A: Lecture 7 ✔...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Page 1 of 31 CSE 8A, UCSD LEC7 CSE 8A: Lecture 7 ✔ Variable visibility ✔ Passing arguments to methods ✔ Returning values from methods ✔ Towards object-oriented programming: Strings and wrapper classes (Reading: Savitch, part of Ch. 4 and Ch. 5) Page 2 of 31 CSE 8A, UCSD LEC7 Midterm Exam #1 Thursday Jan 31, during lecture time Location: lecture room Closed-book, closed-notes, no calculators. Bring something to write with, and picture ID! Coverage: Lectures 1-7, corresponding textbook chapters, Assignments P1-P3 Midterm review will be: today A practice midterm is available online (PDF format) (No key is provided for the practice midterm. It is intended that working through the exam youself will be a useful way to study) Lecture notes are available online... Midterm #1 topic on webboard... Page 3 of 31 CSE 8A, UCSD LEC7 Variables, methods, and computation ✔ A method acts like a black box which you can give information to, and get a computational result back from ✗ (A method might also read input from the keyboard, print output to the terminal window... but these are different from getting input through arguments, and returning a value back to where the method was called) ✔ This information transfer requires variables (regions of computer memory that store information) ✔ We will look more closely at what happens when primitive type values are passed as arguments to methods, and returned from methods Page 4 of 31 CSE 8A, UCSD LEC7 Variable visibility or scope ✔ A method must be defined before it can be used, and a variable must be declared before it can be used... but what does “before” mean? ✔ Like methods, variables have visibility rules, and a variable can only be used where it is visible ✔ Visibility (sometimes called scope ) rules for variables in Java: ✗ a variable declared inside a compound statement (for example, a method body) is visible from the point of declaration to the end of the compound statement (it is “local” in that block) ✗ a variable declared in the argument list of a method header is visible everywhere in the method body (it is local in that method) ✗ a variable declared static in a class outside any method body is visible everywhere in that class (it is “global in the class”) • static variables have a visibility specifier in their declaration • if a static variable is declared private , it is only visible in its class; otherwise it is visible outside the class, in the same way static methods are Page 5 of 31 CSE 8A, UCSD LEC7 Formal arguments as variables ✔ Identifiers in the argument list of a method definition header are the “formal arguments” or “parameters” of the method ✔ These formal arguments act like variables that are visible only in the method body ✗ so variables in the argument list can be used in the method body......
View Full Document

This note was uploaded on 06/12/2008 for the course CSE 8 taught by Professor Marx during the Fall '08 term at UCSD.

Page1 / 31

lec7 - Page 1 of 31 CSE 8A, UCSD LEC7 CSE 8A: Lecture 7 ✔...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online