Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Monday 18 July 2011

Program to Implement Method Overloading in Java


     This is a program to implement method overloading which passes the integer,float,double variable as a argument.

import java.io.*;
import java.util.*;
class Method1
{
            void add(int a,int b)
            {

                        int z;
                        z=a+b;
                        System.out.println("Sum of 2 Integer Numbers: " +z);
            }
            void add(float c,float d)
            {
                        float z1;

                        z1=c+d;
                        System.out.println("Sum of 2 Float Numbers: " +z1);
            }
            void add(double e,double f)
            {
                        double z2;

                        z2=e+f;
                        System.out.println("Sum of 2 Integer Numbers: " +z2);
            }
            void add(String g,String h)
            {
                        String s;
                        s=g+h;
                        System.out.println("Add String:"+s);
            }
}
class Method
{
            public static void main(String args[])
            {
           
                        Method1 m=new Method1();
                        m.add(10,20);
                        m.add(9.0f,10.0f);
                        m.add(10.0,24.0);
                        m.add("JAVA","PROGRAMMING");
               }
}

Output

Sum of 2 Integer Numbers: 30
Sum of 2 Float Numbers: 19.0
Sum of 2 Integer Numbers: 34.0
Add String:JAVAPROGRAMMING

No comments:

Post a Comment

Followers