You are on page 1of 15

4.

0 Java Language

4.5 Method
4.5.3 Static User-defined Method

Learning Outcomes :

At the end of this topic, you should be able to:


(a) Explain two (2) types of static user-defined method.

(1 Hour)
METHOD
METHOD

Predefined METHOD USER-DEFINED METHOD


METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by a programmer


available for use
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by the programmer
available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class
➢ pow () – define in Math class
➢ print () – define in java.io.PrintStream

* Programmers like you, can just use


them without learning their method
definition
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by the programmer
available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class Static Method Non-Static Method
➢ pow () – define in Math class NOT IN YOUR SYLLABUS
➢ print () – define in java.io.PrintStream

* Programmers like you can just use


them without learning their method
definition
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by the programmer
available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class Static Method Non-Static Method
➢ pow () – define in Math class NOT IN YOUR SYLLABUS
➢ print () – define in java.io.PrintStream
❑ Not require an object ❑ Require an object to
to call the method call the method
* Programmers like you can just use
them without learning their method
definition
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by a programmer


available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class Static Method Non-Static Method
➢ pow () – define in Math class
NOT IN YOUR SYLLABUS
➢ print () – define in java.io.PrintStream
❑ Not require an object ❑ Require an object to
to call the method call the method
* Programmers like you can just use
them without learning their method
definition
2 types of User- Defined
Method
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by a programmer


available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class Static Method Non-Static Method
➢ pow () – define in Math class
➢ print () – define in java.io.PrintStream NOT IN YOUR SYLLABUS
❑ Not require an object ❑ Require an object to
to call the method call the method
* Programmers like you can just use
them without learning their method
definition
2 types of User- Defined
Method
METHOD

Predefined METHOD USER-DEFINED METHOD

❖ Built in method in Java that are readily ❖ Methods define by a programmer


available for use
❖ Example :
➢ next() – defined in Scanner class
➢ sqrt () – define in Math class Static Method Non-Static Method
➢ pow () – define in Math class
➢ print () – define in java.io.PrintStream NOT IN YOUR SYLLABUS
❑ Not require an object ❑ Require an object to
to call the method call the method
* Programmers like you can just use
them without learning their method
definition
2 types of User- Defined
Method

Method without a return Method with a return value


value (void) (int, double, float, boolean, char, String)
Based on previous example : 2 terms that you have to know
Calculate and display the multiplication of a and b, c and d, e and f, and h and g.
(Given the value of a = 10, b =5, c = 100, d = 5, e = 100, f = 50, g = 9, h =50)

class UserDefineMethod{//start of class


public static void main(String []args){//start of main

multiply(10,5);
multiply(100,5);
multiply(100,50);
multiply(9,50);
}//end of main

static void multiply (int a, int b){//start of method


System.out.println(a*b);
}//end of method
}//end of class

• User-defined methods must be defined inside a class, and outside main() method.
Based on previous example : 2 terms that you have to know
Calculate and display the multiplication of a and b, c and d, e and f, and h and g.
(Given the value of a = 10, b =5, c = 100, d = 5, e = 100, f = 50, g = 9, h =50)

class UserDefineMethod{//start of class


public static void main(String []args){//start of main

multiply(10,5);
multiply(100,5);
1. Method Calls
multiply(100,50);
multiply(9,50);
}//end of main

static void multiply (int a, int b){//start of method


System.out.println(a*b);
}//end of method
}//end of class

• User-defined methods must be defined inside a class, and outside main() method.
Based on previous example : 2 terms that you have to know
Calculate and display the multiplication of a and b, c and d, e and f, and h and g.
(Given the value of a = 10, b =5, c = 100, d = 5, e = 100, f = 50, g = 9, h =50)

class UserDefineMethod{//start of class


public static void main(String []args){//start of main

multiply(10,5);
multiply(100,5);
1. Method Calls
multiply(100,50);
multiply(9,50);
}//end of main

static void multiply (int a, int b){


System.out.println(a*b); 2. Method
}//end of method Definitions

}//end of class
Based on previous example : 2 terms that you have to know
Calculate and display the multiplication of a and b, c and d, e and f, and h and g.
(Given the value of a = 10, b =5, c = 100, d = 5, e = 100, f = 50, g = 9, h =50)

class UserDefineMethod{//start of class


static void multiply (int a, int b){
2. Method
System.out.println(a*b);
Definitions
}//end of method

public static void main(String []args){//start of main

multiply(10,5);
multiply(100,5); 1. Method Calls
multiply(100,50);
multiply(9,50);
}//end of main
}//end of class

• User-defined methods must be defined inside a class, and outside main() method.

You might also like