Saturday, June 23, 2018

WAP IN JAVA TO SHOW THE USE OF METHOD OVERLOADING

class MethodOverloading
{
    int a,b;
    void calc(int x)
    {
        a=x;
        System.out.println("Square of the number: "+(a*a));
    }
    void calc(int x, int y)
    {
        a=x;
        b=y;
        System.out.println("Addition of two numbers: "+(a+b));
    }
}
public class Tenth{
    public static void main(String args[])
    {
        MethodOverloading obj=new MethodOverloading();
        obj.calc(20,35);
        obj.calc(6);
    }
 
}


No comments:

Post a Comment