Download presentation
Presentation is loading. Please wait.
Published byMay Stafford Modified over 9 years ago
1
Creating and Using Class Methods
2
Definition Class Object
3
Class Methods Math methods are an example Can be either void or return Can have parameters or not Must be static Should be public Know how to invoke (call) Be able to evaluate
4
Parameters Actual vs Formal Formal In the method definition Must have data types Actual In the method call Cannot have data types Must match the formal parameters in type, quantity and sequence
5
Void methods Can have parameters or not Have the keyword void in the heading
6
Return methods Can have parameters or not Do not have the keyword void in the heading Have a return statement in the body of the method
7
Math methods floor ceil round
8
Random values Use Math.random() Multiply times the range + 1 Add the small value To produce integer values, cast the result to be an integer Example, to produce a random value between 1 and 10: int x = (int)(Math.random() * 10 + 1);
9
String Methods length charAt indexOf equals
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.