Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Method Overloading using Java

class Area
{
    int s1,s2,s3;
    void Area(int s1)
    {
        int a;
        this.s1=s1;
        a=this.s1*this.s1*3.141;
        System.out.println("The area of circle is"+a);
    }
    void Area(int l,int b)
    {
        int a;
        s1=l;
        s2=b;
        a=s1*s2;
        System.out.println("The area of rectangle is"+a);
    }
    void Area(int a,int b,int c)
    {
        int s,ar;
        s1=a;
        s2=b;
        s3=c;
        s=(s1+s2+s3)/2;
        ar=(s*(s-s1)*(s-s2)*(s-s3))^(1/2);
        System.out.println("The area of triangle"+ar);
    }
}
public class AreaDemo
{
    public static void main(String args[])
    {
        Area a1=new Area();
        a1.Area(5);
        a1.Area(5,10);
        a1.Area(5,6,7);
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.