Publish your story - poem - jokes free online--click here

JAVA

Method Overloading Early Data Binding in Java

Polymorphism
Polymorphism is a technique to define a function (method) more than one in different way.

Types of polymorphism:--

1>> Compile time polymorphism (early data binding)
                a>> Method overloading
2>> Runtime time polymorphism (late data binding)
                b>> Method overriding

Method overloading

Using this concept you can define more than one function with same name but different parameter.
Note: -- this parameter can vary on following basis.
                a>> number of parameter
                b>> type of parameter
                c>> sequence of parameter
                                Ex:-
                                void fun(int);
                                void fun(int,int);
                                void fun(char,int);
                                void fun(int,char);

Method overloading is called compile time polymorphism or early data binding because the execution paradigm of the different method is decided at the time of compilation by matching its arguments types and passed parameter.

NOTE: -- Method overloading can be achieved within the single.

Example of Method Overloading

import java.util.*;
class overloading
{
                Scanner in=new Scanner(System.in);
                void fun()
                {
                                int a,b,c;
                                System.out.println("enter two number");
                                a=in.nextInt();
                                b=in.nextInt();
                                c=a+b;
                                System.out.println("sum of two integer=="+c);
                }
                void fun(int a,int b)
                {
                                int c=a-b;
                                System.out.println("difference of two varibale=="+c);
                }
                void fun(String s1,String s2)
                {
                                String s=new String();
                                s=s1.concat(s2);
                                System.out.println("addition of two string=="+s);
                }
}
public class abc
{
                public static void main(String as[])
                {
                                                overloading o=new overloading();
                                                o.fun();
                                                o.fun(10,45);
                                                o.fun("I Love ","INDIA");
                }
}

For Runtime Polymorphism click HERE  
http://shvicyberteam.blogspot.com/p/method-overriding.html


No comments:

Post a Comment