Function Overloading Example in Java


Here is the simple program for printing basic example using Function Overloading Example in Java.

Source Code

import java.io.*;
import java.util.Scanner;
//www.tutorjoes.com
class fun_overload
{
  public static void main(String args[])
  {
    fun o1 =new fun();
    o1.display();
    fun o2 =new fun(25,25,25);
    o2.display();
    o2.display(45);
  }
}
class fun
{
  private int a,b,c;
  fun()
  {
    a=10;
    b=20;
    c=a+b;
  }
  fun(int x,int y,int z)
  {
    a=x;
    b=y;
    c=z;
    c=c+a+b;
  }
  public void display()
  {
    System.out.println("Total : " +c);
  }
  public void display(int x)
  {
    System.out.println(x+" Total : " +c);
  }
}
To download raw file Click Here

Output

Total : 30
Total : 75
45 Total : 75


Learn All in Tamil © Designed & Developed By Tutor Joes