Sunday 15 June 2014

Program to show function overloading

import javax.swing.JOptionPane;

class over
{
int a,b;
public void in()
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));

}
public void add()
{
int k=a+b;
System.out.print("\nsum="+k);
}
public void add(int k, int m)
{
int c=k+m;
System.out.print("\nsum="+c);
}
public int add(int q, int w, int e)
{
return (q+w+e);
}
}
public class overloading {

public static void main(String[] args) {
over t=new over();
t.in();
t.add();
t.add(2,4);
int l=t.add(1,2,3);
System.out.print("\nsum="+l);


}

}

output
enter a 2
enter b 3
sum=5
sum=6
sum=6

No comments:

Post a Comment

SAY HELLO!!