Saturday, July 22, 2023

Area Calculation Using Function Overloading in java

 

class ShapesArea
{
    void area(double r)
    {
        System.out.println(Math.PI*Math.pow(r, 2));//circle
    }
    void area(int a)
    {
        System.out.println(Math.pow(a, 2));//square
    }
    void area(int x,int y)
    {
        System.out.println(x*y);//rectangle
    }
    void area(int p,int q,int r)
    {
        double s = (p+q+r)/2;
        System.out.println(Math.sqrt(s*(s-p)*(s-q)*(s-r)));
    }
}
public class AreaCalculate {
    public static void main(String[] args) {
        ShapesArea ob=new ShapesArea();
        ob.area(9.5);
        ob.area(6);
        ob.area(3, 4);
        ob.area(7, 8, 9);
    }
}


No comments:

Post a Comment

A physicist confesses that the electron is round and that Jesus rose from the dead. (Bengali)

একজন পদার্থবিজ্ঞানী স্বীকার করেন যে ইলেকট্রন গোলাকার এবং যিশু মৃতদের মধ্য থেকে পুনরুত্থিত হয়েছিলেন। আমার নিজের বিশ্বাস প্রমাণ দ্বারা প্রভাব...