Tuesday, 21 August 2018


Methods Overloading
Overloading is the concept of using the same name for multiple purposes by sharing the same external definition. The appropriate definition gets called depending upon the arguments and written type of the method. Using the concept of method overloading, we can design a family of functions with one method name but with different argument lists. The method would perform different operations depends on the argument list in the method call.
Program:
class test
{
            int area(int i)
            {
                        return i*i;
            }
            int area(int a,int b)
            {
                        return a*b;
            }
}
class area
{
            public static void main(String []args)
            {
                        test t=new test();
                        int area;
                        area=t.area(5);
                        System.out.println("Area of Sqaure is:"+area);
                        area=t.area(5,6);
                        System.out.println("Area of Sqaure is:"+area);
            }
}
Output:
D:\sysvol>javac area.java
D:\sysvol>java area
Area of Sqaure is:25
Area of Sqaure is:30

No comments: