Function Overloading Java Polymorphism

This Simple Java is for performing Function Overloading / Compile Time Polymorphism. This is a part of Mumbai University MCA Colleges Java Practicals.

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);
}
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.

No comments:

Post a Comment