Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet48/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   44   45   46   47   48   49   50   51   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

How To Create Methods
Considering the accompanying sample to clarify the structure of a method:
public static int functionname(int x, int y) {
//Statements
}
Here, the method uses the following elements:
Modifier: public static
Data type of the return value: int
Method name: functionname
Formal Parameters: x, y
Such  constructs  are  otherwise  called  Functions  or  Procedures.  However,  there  is  a
distinctive quality of these two:
Functions: They return an explicit value.
Procedures: They don’t give back any quality.
Function definition comprises of a system header and body. The construct given above can
be generalized to the following arrangement:
modifier returndatatype methodname (List of Parameter) { //Statements }
The structure indicated above incorporates:
Modifier:  It  characterizes  the  right  to  gain  entrance  to  the  method  and  it  is  non-
compulsory to utilize.
Returntype: Method may give back a value of this data type.
Methodname:  This  is  the  method  name,  which  comprise  of  the  name  and  the


parameter list of the method.
List  of  Parameters:  The  rundown  of  parameters,  which  entails  data  type,  request,
and number of parameters of a method. A method may contain zero parameters as
well.
Statements:  The  method  body  characterizes  what  the  method  does  with
explanations.
Sample Implementation:
Here is the source code of the above characterized method called maxval(). This technique
takes  two  parameters  number1  and  number2  and  furnishes  a  proportional  payback
between the two:
public static int minval(int num1, int num2) {
int minvalue;
if (num1 > num2) minvalue = num2;
else minvalue = num1;
return minvalue;
}

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   44   45   46   47   48   49   50   51   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling