Daffodil International University
 Submitted By
Niloy Biswas (171-35-225)
 Submitted to
 S A M Matiur Rahman
Associate Head
Department of SWE
Daffodil International University
Methods
 A program that provides some functionality can be long and
contains many statements
 A method takes input, performs actions, and produces output
 In Java, each method is defined within specific class
General from of Method
Int square ( int num1, int num2){
//body of method
}
Type name parameter
General from of Method
• The parameter list is a sequence of type and identifier pairs separated by
commas.
• Parameters are essentially variables that receives the value of the arguments
passed to the method when it is called.
• If the method has no parameters, then the parameter list will be
empty.
• Methods that have a return type other than void return a value to the calling
routine using the following form of return statement.
Method declaration
public static void main (String[ ] args){
System.out.println(“This is method body”);
}
ParameterModifier Modifier ReturnType Nameof Method
Methodbody
Adding a Method to class
class Box{
float width;
float height;
float depth;
float volume() {
return width * height * depth;
}
}
Method of java

Method of java

  • 2.
    Daffodil International University Submitted By Niloy Biswas (171-35-225)  Submitted to  S A M Matiur Rahman Associate Head Department of SWE Daffodil International University
  • 3.
    Methods  A programthat provides some functionality can be long and contains many statements  A method takes input, performs actions, and produces output  In Java, each method is defined within specific class
  • 4.
    General from ofMethod Int square ( int num1, int num2){ //body of method } Type name parameter
  • 5.
    General from ofMethod • The parameter list is a sequence of type and identifier pairs separated by commas. • Parameters are essentially variables that receives the value of the arguments passed to the method when it is called. • If the method has no parameters, then the parameter list will be empty. • Methods that have a return type other than void return a value to the calling routine using the following form of return statement.
  • 6.
    Method declaration public staticvoid main (String[ ] args){ System.out.println(“This is method body”); } ParameterModifier Modifier ReturnType Nameof Method Methodbody
  • 7.
    Adding a Methodto class class Box{ float width; float height; float depth; float volume() { return width * height * depth; } }