07-methods - Methods and Code Reuse CSE 114 Computer...

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

View Full Document Right Arrow Icon
Methods and Code Reuse CSE 114: Computer Science I SUNY at Stony Brook 1
Background image of page 1

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

View Full Document Right Arrow Icon
What is a Method? Remember that laziness is a virtue (for programmers) You should always try to avoid writing duplicate code A method is a way to group related statements together so that they can be reused Synonyms: function, procedure, or subprogram Invoking a method tells Java to re-execute that code 2
Background image of page 2
Calling Methods Messages tell objects to perform services A message consists of the object’s name, followed by a “dot” (period), followed by the method name and argument list Messages are terminated by a semicolon karel.move(); Reference to an object Method to execute Argument list 3
Background image of page 3

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

View Full Document Right Arrow Icon
A method defnition consists oF a method header and a method body The method header specifes the return type, name, and arguments list Ex. public static void main(String[] args) The method body is a brace-enclosed set oF 0 or more program statements 4
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 16

07-methods - Methods and Code Reuse CSE 114 Computer...

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

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