Category of Method

Author: Ravi Poswal

Four categories of method in java 

1. without return type and without parameter

2. with return type and without parameter

3. without return type and with parameter

4. with return type and with parameter

Code Example

// without return type and without parameter
class Method
{
void ab()
{   System.out.println("without parameter and without return type");
}
public static void main(String ar[])
{
Method m1=new Method();
m1.ab();
}
}

Code Example

// with return type and without parameter
class Method
{
int ab()
{
   System.out.println("without parameter and with return type");
return 0;
}
public static void main(String ar[])
{
Method m1=new Method();
m1.ab();
}
}

Code Example

// without return type and with parameter
class Method
{
void ab(int x,int y)
{   System.out.println("with parameter and without return type "+x +" "+y);
}
public static void main(String ar[])
{
Method m1=new Method();
m1.ab(10,20);
}
}

Code Example

// with return type and with parameter
class Method
{
int ab(int x,int y)
{   System.out.println("with parameter and with return type "+x +" "+y);
return 0}
public static void main(String ar[])
{
Method m1=new Method();
m1.ab(10,20);
}
}