1.

11. Write a program in Java by using function overloading technique to compute the area of(a) a circle using formula 22/7*r*r(b) a square(c) a rectangleDisplay the menu and area as per user's choice

Answer»

class OverloadDemo

{

void area(float x)

{

System.out.println("the area of the square is "+Math.pow(x, 2)+" sq units");

}

void area(float x, float y)

{

System.out.println("the area of the rectangle is "+x*y+" sq units");

}

void area(double x)

{

double z = 3.14 * x * x;

System.out.println("the area of the circle is "+z+" sq units");

}

}

class Overload

{

public static void main(String args[])

{

OverloadDemo ob = new OverloadDemo();

ob.area(5);

ob.area(11,12);

ob.area(2.5);

}

}



Discussion

No Comment Found