CS2_09_Methods

CS2_09_Methods - CS2 Module 9 Category: Elements of Java...

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

View Full Document Right Arrow Icon
CS2 Module 9 Category: Elements of Java Topic: Methods Objectives Describe all that is important regarding methods including main.
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 2 Introduction to Object Oriented Programming Module 9 Elements of Java Methods
Background image of page 2
Method Madness
Background image of page 3

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

View Full DocumentRight Arrow Icon
Methods Recall that the OO paradigm calls for us to encapsulate data and behavior inside of the object (defined by the class). The method is the tool to accomplish the behavior part. Methods are "sort" of like procedures and functions in other languages Procedures may be passed some data and they perform some operation Functions may be passed some data and they perform some operation and then return a value
Background image of page 4
Methods Methods may be passed data Methods can perform operations using the data passed in as well as the data held by the object They only occur inside of a class They effectively allow us to send an object a message telling it to do something They may return a value like a function
Background image of page 5

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

View Full DocumentRight Arrow Icon
Note the comment Methods with no return value Use the keyword void to indicate that this method has no return value. public void printHelloWorld( ) { System.out.println("Hello World!"); } // of printHelloWorld Note: All methods must have parentheses for the parameter list . . .even if there are no parameters! It's how Java knows it's a method!
Background image of page 6
Methods with no return value A method may use value defined in the class public void printX( ) { System.out.println(x); } // printX x must be a value declared in the class
Background image of page 7

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

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

Page1 / 23

CS2_09_Methods - CS2 Module 9 Category: Elements of Java...

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

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