Methods
Static : No Need to Create object,Directly we call from class
Void: Nothing will return only Executs and display
Method:
A method is a block of code which only runs when it is called.
You can pass data, known as parameters, into a method.
Why use methods?
1.To reuse code: define the code once, and use it many times.
2.Readability
3.Saves Memory
syntax:
<Access_Modifier> <Return Type> <Method Name>(Parameter List) {
Method Body
}
EX:
public int FindMax(int num1, int num2) {
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Types:
1.Example Program Without Parameters & Without Return Type
2.Example Program Without Parameters & With Return Value Type
3.Example Program With Parameters & Without Return Value Type
Comments
Post a Comment