Professional Documents
Culture Documents
4.5.3 (B)
4.5.3 (B)
0 Java Language
4.5 Method
4.5.3 Static User-defined Method
Learning Outcomes :
return type
method header
method name
parameter
method body
The general structure of a static user-defined method
Consists of : In Java, how does it look like ? (syntax)
modifier
return type
method name
parameter
method body
The general structure of a static user-defined method
Consists of : In Java, how does it look like ? (syntax)
method header
modifier
parameter }
How to remember???..
method body
* mo re ty me nam (par) Mu ReTi MeNamPar..
☺
The general structure of a static user-defined method
Consists of : In Java, how does it look like ? (syntax)
method header
modifier
parameter }
{
method body
method body
Or other example :
From previous example :
2.
1. static String displayText( ){
static void multiply(int a, int b){
System.out.print ( a * b ); return “Message is printed”;
} }
The general structure of a static user-defined method
In Java, how does it look like ? (syntax)
method header
Or other example :
From previous example :
2.
1. static String displayText( ){
static void multiply(int a, int b){
System.out.print ( a * b ); return “Message is printed”;
} }
The general structure of a static user-defined method
In Java, how does it look like ? (syntax)
method header
1.
static void adam ( ){
adam method body could have 4 cases :
}
return value parameter
1 x x
Explain method return types based on return values
1.
static void adam ( ){
adam method body could have 4 cases :
}
return value parameter
1 x x
2 x /
2.
static void adam ( int a ){
adam method body
}
Explain method return types based on return values
1. 3.
static void adam ( ){ static int mark ( ){
// adam method body could have 4 cases : // method body
} return…;
return value parameter }
1 x x
2 x /
3 / x
2.
static void adam ( int a ){
// adam method body
}
Explain method return types based on return values
1. 3.
static void adam ( ){ static int mark ( ){
// adam method body could have 4 cases : // method body
} return…;
return value parameter }
1 x x
2 x /
3 / x
4.
2. 4 / / static int mark ( int a , int b){
static void adam ( int a ){ // method body
// adam method body return…;
} }
Explain method return types based on return values
1.
static void adam ( ){
// body of adam method
//must have System.out.print
could have 4 cases :
}
Return
Return type Parameter
value
1 x x
void
2 x /
2.
static void adam ( int a ){
// body of adam method
//must have System.out.print
}
Explain method return types based on return values 3.
1. static int mark ( ){
static void adam ( ){ // body of method
// body of adam method // must have return
//must have System.out.print }
could have 4 cases :
} Return
Return type Parameter
value
1 x x
void
2 x /
3 int, double, boolen, float, / x
4 char, String / /
2. 4.
static void adam ( int a ){ static int mark ( int a , int b){
// body of adam method // body of method
//must have System.out.print // must have return
} }
Let’s open up our mind a little bit
bigger ….
And take a look at a complete source code. (Please copy this source code down)
Main Method
Method 1
Method 2
Method 3
Method 4
Still remember this? :P
return
parameter explanation
value
returnType void
methodName borrowBank
Method body
int dueDate = dateBorrow + 7;
if(daysLate < 3)
fine = daysLate * 0.50;
else
fine = 1.00 + ((daysLate - 2) * 0.20);
return fine;
EXERCISE
Still remember this? :P
return
parameter explanation
value