Urgenthomework logo
Live chat


Java Methods Homework Help

Java Methods:

In java method is a collection of statements it is used to perform some operation. Depends on user needs they create own method with argument or without argument and with return type or without return type.

Method creation:


Modifier returntype methodname( argumentlist)

{ ;

Body of the content



Public static void add( int a, int b )
{  ;
Int c;
c= a+b;
}  ;
  • Public, static – modifiers
  • Void – return type (nothing return)
  • Add – method name
  • Int a, int b – argument list

Method calling:

There are two ways to call the method that is with return type or without return type.


If it have return type then

Datatype variable = methodname(arguments);

If no return type means


Passing parameters by value:


In this example using pass by value method will executed.

{`public class sample
{  ;
 public static void main(String[] args)
 {  ;
 int x = 20;
 int y = 15;
int z;
 // Invoke the method
 Z=add(x, y);
 System.out.println("addition value is :" + z);
 }  ;
 public static int add(int x, int y)
  {  ;
 // add x with y
int a;
return a;
}  ;
}  ;


Addition value is : 35

Copyright © 2009-2023 UrgentHomework.com, All right reserved.