Your Only Destination To Empower Your Computer Programing Knowledge. Sky is not so high, You can Touch it if You Try

Program to show concept of overloading.

import java.util.*;
class Overl
{
int a;
double area(double r)
{
return 3.14*r*r;
}
double area(double l,double b)
{
return l*b;
}
int area(int a)
{
return a*a;
}
}
class Main
{
public static void main(String ar[])
{
Overl o1=new Overl();
double c,d;
int n;
c=o1.area(5.2);
System.out.println("area of circle is="+c);
d=o1.area(2.3,2.3);
System.out.println("area of rectangle is="+d);
n=o1.area(4);
System.out.println("area of square is="+n);
}
}

Output:-


C:\Documents and Settings\Administrator>cd\

C:\>cd\java\bin

C:\java\bin>javac Main.java

C:\java\bin>java Main
area of circle is=84.90560000000002
area of rectangle is=5.289999999999999
area of square is=16

C:\java\bin>

No comments:

Post a Comment