×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Numbers Program In Java Java Inheritance
Java Method Overloading - Java
3412    Arnab De    16/07/2017

What is functions or method overloading?


Two or functions or method with same name but different signature or header, can define within a class in Java. This programming concept is known as function overloading or method overloading.

 

Note: Signature can differ by the
  1. Change of the data types
  2. Numbers of the arguments
  3. Sequence of the arguments.
softetechnologies

But if we change the data type from float to double or for it to short, long or byte, then function overloading is not executed properly due to type promotion of the data types.

Note: Method overloading is also known as Compile time binding or Early Binding.

softetechnologies


Example of Function Overloading

import java.util.*;
public class JavaPower{
public int Power(int a){
return a*a;
}
public int Power(int a,int n){
int m=1;
for(int i=0;i<n;i++){
m=m*a;
}
return m;
}
public static void main(String []args){
int a,n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter A Number : ");
a=sc.nextInt();
System.out.print("Enter A Power : ");
n=sc.nextInt();
JavaPower jp=new JavaPower();
System.out.println( a + " Square = " + jp.Power(a));
System.out.print(a + " To The Power = " + jp.Power(a,n));
}
}

Numbers Program In Java Java Inheritance
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
The world is needed a mixture of truth and make-believe. Discard the make-believe and take the truth.
Sri Sri Ramakrishna Paramahamsa
1135
60.61
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44721
01/01/2018     36882
25/06/2018     36855
28/06/2017     34896
02/08/2017     33492
01/08/2017     27840
06/07/2017     27613
15/05/2017     27180
14/07/2017     22943
11/09/2018     21679
softetechnologies