Static Method in Java with Example

Static Method in Java:

In Java, a class contains two sections, one declares variables and the other declares methods. A static member is a member that is common to all the objects and accessed without using a particular object. This member belongs to the class as a whole rather than the objects created from the class. It has the following Syntax:

static int count;
static int add(int a, int b);

Program :

class Math
{
static int multi(int a, int b)
{
return a*b;
}
static int divide(int a, int b)
{
return a/b;
}
}
class test
{
public static void main(string arg[])
{
int p=Math.multi(20, 5);
System.out.println("Multiplication :"+p);
int q=Math.divide(24, 6);
System.out.println("Division :"+q);
}
}