Function Overloading Java Polymorphism

Ram Pothuraju

THIS SIMPLE JAVA IS FOR PERFORMING FUNCTION OVERLOADING / COMPILE TIME POLYMORPHISM. 

Function Overloading or Polymorphism is the concept of using Same Function Name (Different Signatures) to perform differently.

The Below java program calculates the areas of Circle, Triangle and Rectangle with same name function but different signatures.


class Area
{
void area(int l,int b)
{
          System.out.println("AREA OF RECTANGLE ="+(l*b));
}
void area(double b,double h)
{
System.out.println("AREA OF TRIANGLE ="+(0.5*b*h));
}
void area(double r)
{
System.out.println("AREA OF CIRCLE ="+(3.14*r*r));
}
public static void main(String args[])
{
Area a=new Area();
a.area(10.5,20.4);
a.area(2,6);
a.area(15.3);
}
}

Tags

Post a Comment

0Comments

Post a Comment (0)