Sunday, 12 March 2023

6. Write a program to calculate the area of square and rectangle by overloading the area method.

 



class Example
{
    void area(float x)
    {
        System.out.println("Square area: " + x*x);
    }
       
    void area(float x, float y)
    {
        System.out.println("Rectangle area: " + x*y);
    }
}

class Program6
{
    public static void main(String args[])
    {
        Example e1 = new Example();
        e1.area(5);
        e1.area(5,7);
    }
}


No comments:

Post a Comment

python programs

1. sum of two number