Oct 2, 2013

static method void return type primitive parameter

static method with void return type with primitive parameter: Lets describe what is the mean of static method whose return type is primitive and it has primitive parameter. void return type i.e. it does not returns any type of value and primitive parameter means it has a parameter like int, char, float etc.... static method means it can be called with class name i.e. there is no need to create the object of the class for calling this method. A program for this tutorial is given below-

class Sm
{
 static void abc(int a,boolean b)
  {
    System.out.println("inside static method of abc of class Sm");
  }
public static void main(String args[])
  {
   int a=20;
   boolean c=true;
   Sm.abc(a,c);
  }
}

Explanation:
In this program we can also call abc() method directly without class name because within the same class we can call static method with or without class name.
For Example:
class Sm1
{
 static void abc1(int a,boolean b)
  {
    System.out.println("inside static method of abc of class Sm");
  }
public static void main(String args[])
  {
   int a=20;
   boolean c=true;
   abc1(a,c);
  }
}

Related posts: