Presentation is loading. Please wait.

Presentation is loading. Please wait.

Method Mark and Lyubo.

Similar presentations


Presentation on theme: "Method Mark and Lyubo."— Presentation transcript:

1 Method Mark and Lyubo

2 Purpose to break down larger tasks into smaller ones to organize code

3 Declaring a method public static void drawBar (int length) {
<return type> <parameters> <name> public static void drawBar (int length) { System.out.print("*"); } <access level> <statements>

4 Access level determines if the method can be called by other classes
is either public or private Ex: public static void drawBar (int length)

5 Return type Declares if the method will return a value
Ex: double, char, and int void will not return a value Ex: public static void drawBar (int length)

6 Name the name of the method
starts with a lowercase and if there is more words the following words will be uppercase in no case do you add spaces public static void drawBar (int length)

7 Parameters values are used in a method
parameters are enclosed by brackets parameters must be separated with commas Ex: public static void drawBar (int length)

8 Method declaration the keyword static in the method declaration makes the method able to be called from the class it is in Ex: public static void sumNum (int num1, int num2) { } If the return type is not void the return statement must be in the method

9 types of parameters types of parameters: formal and actual
Ex: public void setText (String text) setText(“bob”); formal parameter actual parameter

10 Return Statement used when return type is other than void is specified in the method declaration return statement sends a value back to the method call can’t contain more than 1 value Ex: public static int areaOf(int size) { int area; area = size * size; return(area); }


Download ppt "Method Mark and Lyubo."

Similar presentations


Ads by Google