lec6 - CSE 8A: Lecture 6 Static methods Static method...

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

View Full Document Right Arrow Icon
Page 1 of 24 CSE 8A, UCSD LEC6 CSE 8A: Lecture 6 Static methods Static method visibility, and calling static methods Passing arguments to methods, and returning values Some programming problems (Reading: Savitch, part of Ch. 4 and Ch. 5)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Page 2 of 24 CSE 8A, UCSD LEC6 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: Lecture before exam 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. ..
Background image of page 2
Page 3 of 24 CSE 8A, UCSD LEC6 Methods A method (or function, or procedure) is a sequence of statements that has. .. a way to refer to it its name (an identifier) a way to give information to it a specification of the number, ordering, and types of its arguments a specification of its return value type (or void if none) A method’s sequence of statements form a compound statement, called the body of the method The method body may compute a return value (or not), and may perform side effects (or not)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Page 4 of 24 CSE 8A, UCSD LEC6 Methods as “black boxes” From the point of view of the user of a method, it can be treated as a “black box”: to use the method, the user doesn’t need to know how it works, only what it does (As a programmer of a method, of course you need to know how it works!) a method output information (return value) input information (arguments) other information side effects (from keyboard, mouse, files, . ..) (display data, change variables, . ..)
Background image of page 4
Page 5 of 24 CSE 8A, UCSD LEC6 Static and instance methods There are two kinds of methods that can appear inside a Java class: static methods instance methods If you use the keyword static in the method header (just before the return type), it is a static method; if you do not use that keyword, it is an instance method A static method is associated with the class within which it is defined You do not need to create an object that is an instance of the class to use (invoke or call) a static method Static methods are also called “class methods” An instance method is associated with each object that is an instance of the class within which it is defined You (or someone) must create an object that is an instance of the class to use (invoke or call) an instance method We will concentrate on static methods first (objects not needed!)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Page 6 of 24 CSE 8A, UCSD LEC6 Defining static methods A header of a static method has the form <visibility> static <typename> <identifier>(<parameterlist>) <visibility> is either public , private , protected , or (if missing) package <typename> specifies the datatype of value the method returns (or
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the 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 / 24

lec6 - CSE 8A: Lecture 6 Static methods Static method...

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

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