Function Overloading

5 comments - Post a comment

/* Function Overloading program in java. The program overloads the area() function and calculates the area for square, rectangle and triangle */

class overloading
{
double area,root;
//Area Of Square
public void Area(double a)
{
area = a*a;
System.out.println("The Area Of Square : " +area);
}

// Area of rectangle
public void Area(double a,double b)
{
area= a*b;
System.out.println("The Area Of Rectangle : " +area);
}

// Aera Of Triangle
public void Area(double a,double b,double c)
{
double s= (a+b+c);
root = s*(s-a)*(s-b)*(s-c);
area = Math.sqrt(root);
System.out.println("The Area Of Triangle : " +area);
}

public static void main(String args[])
{
overloading ar = new overloading();
ar.Area(5.65);
ar.Area(5.32,43.2);
ar.Area(4,7,7);
}
}
/* Output
The Area Of Square : 31.922500000000003
The Area Of Rectangle : 229.82400000000004
The Area Of Triangle : 174.61958653026298 */

 
This Post has 5 Comments Add your own!
Anonymous - March 26, 2009 at 11:31 AM

this is wrong because functions in java never called with the objects

Lionel - March 27, 2009 at 1:28 PM

i m sure this is right..

Anonymous - August 3, 2011 at 8:46 PM

object is not needed in call statement since main fn is in the same class

Anonymous - August 27, 2011 at 8:10 PM

THIS PROGRAM IS RIGHT

Anonymous - November 14, 2011 at 6:26 PM

thnx man...

Post a Comment