« Home | Program to reverse a string » | XML Parser in Java » | Algorithms Used in Garbage collection » | Lower Case to Uppre Case Conversion » | PRINTING THE NON-PRIMES » | PRIME FACTORS OF ALL NON-PRIMES BELOW 500 » | What is Garbage Collection & Why is Garbage Collec... » | Public static void main (String args[]) » | Delete and Update values in MySql Using Java » | Insert values into table Using Java » 

Thursday, April 06, 2006 

What is overloading in java

In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case,the methods are said to be overloaded, and the process is referred to as method
overloading. Method overloading is one of the ways that Java implements polymorphism.

Sample program of overloading:

class Overloading {
void test() {
System.out.println("No parameters");
}

void test(int a, int b) {
System.out.println("a and b: " + a + " " + b);
}

void test(float a) {
System.out.println("Inside test(double) a: " + a);
}
}
class Overload {
public static void main(String args[]) {
Overloading ob = new Overloading();
int i = 88;
ob.test();
ob.test(10, 20);
ob.test(i);
ob.test(123.2);
}
}

This comment has been removed by the author.

one of the important future in any programing language to use names.well-choosen names make it eaiser to you and others to understand your code well.other languages never used methodoverloading.methodoverloading is the one of the most useful feature in java programing language.
MethodOverlaoding:
-----------------
it is possible to define the two or more methods with in the same class and shares with the same name.here methods are said to be overloaded.enitre process is called methodoverloading.and prameter list are different for each method.
Example:
--------
Class MethodOverload{
void draw(){
System.out.println("No Parameters");
}
void draw(int a){
System.out.println("Single Parameter"+a);
void draw(int a,int b){
System.out.println("The values of a and b is givien by"+a+" "+b);
}
double draw(double a){
System.out.println("Here Double Value is givien by"+a);
return a*a;
}
public static void main(String args[])throws Exception{
MethodOverload mo=new MethodOverload();
mo.draw();
mo.draw(10);
mo.draw(10,20);
mo.draw(1.4);
}
}
in the above line of the code
draw method is overload four times.
and each method have parameter list is different.

Hi Sir in your program there ia an error u missed one brace in line 7 in MethodOverload

Post a Comment

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com