Sunday, October 21, 2012

Java program to illustrate method overloading


class area
{
  int l,b,r;
  float s;
  void sample(int l,int b)
  {
   s=b*l;
   System.out.println("area of rectangle="+s);
  }
  void sample(int r)
   {
    s=r*r;
    System.out.println("area of square="+s);
   }
  public static void main(String s[])
   {
     area a=new area();
     a.sample(5,3);
     a.sample(6);
   }
}

Output

No comments:

Post a Comment