In Java A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method.
public class tut5 {
static int sum(int x, int y){
int c = x+y;
return c;
}
// method overloading...
static int sum(int x, int y, int z){
return x+y+z;
}
static float sum(float a, float b){
return a+b;
}
public static void main(String[] args) {
System.out.println(sum(2, 4)); // int
System.out.println(sum(2, 3, 4)); // int
System.out.println(sum(23.07f, 30.06f)); // float
}
}
1 Comment
[…] thread isΒ a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. […]