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);
}
}
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.
Posted by Unknown | 3:33 AM
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.
Posted by Unknown | 2:02 AM
Hi Sir in your program there ia an error u missed one brace in line 7 in MethodOverload
Posted by ram | 2:11 AM