what is overloading in java?
Answers were Sorted based on User's Feedback
Answer / narendher sharma
Methodoverloading occurs with in the class..
Methodoverloading will not involve in Inheritance ..
Method overloading means whic is same method name with
different arguments and parameters may be same may not be
same..
Methodoverloading is call as Compiletime polymorphism which
refers as static polymarphism..
Is This Answer Correct ? | 76 Yes | 15 No |
Answer / ak
Overloading is when the same method or operator can be used
on many different types of data.
For instance the + sign is used to add ints as well as
concatenate strings. The plus sign behaves differently
depending on the type of its arguments. Therefore the plus
sign is inherently overloaded.
Methods can be overloaded as well..same method with
different parameters is said to be method overloading.----
we can perform the similar operation in different ways for
different parameters.
Constructors can be overloaded as well...Overloaded
constructors provide multiple ways to initialize a new object
Is This Answer Correct ? | 69 Yes | 12 No |
Answer / irshad ahmad
Method overloading in java:
create more than one methods that have same name, but
different parameter lists and different definitions, within
a class.
It is used when objects are required to performed similar
tasks but with using different input parameter list.
class ABC
{
int x,y,z;
void star(int a,int b,int c)
{
x=a; y=b;z=c;
}
void star(int a,int b)
{
x=a; y= z=b;
}
void star(int a)
{
x= y= z= a;
}
int result()
{
return(x*y*z);
}
}
Is This Answer Correct ? | 43 Yes | 18 No |
Answer / vijayakumar chinnasamy
Method overloading:
More than one method have same name but different type
of argument or differnt no. of arguments available in same
class or it subclass is called overloading.
Return type of method and access specifier of method is
not a problem in method overloading.
class A{
void diaplay(int a,int b){ }
void display(float a,float b){ }
void display(float a, int b){ }
void display(int a,int b){
void display(){ }
}
Is This Answer Correct ? | 46 Yes | 22 No |
Answer / srujana
To define one or more methods within the same class that
share the same name, as long as thier parameters
declarations are diffrent.These methods are called
overloaded and its process is called Methodoverloading.
For example,
class Demo
{
void test()
{
System.out.println("No parameters");
}
void test(int a)
{
System.out.println("a is:"+a);
}
void test(int a, int b)
{
System.out.println("a is:"+a "," +b);
}
}
class Demo1
{
public static void main(String args[])
{
Demo1 d=new Demo();
d.test();
d.test(5);
d.test(2,3);
}
}
Is This Answer Correct ? | 27 Yes | 9 No |
Answer / sivaprasad addepalli
Method Overloading comes into picture when there are two
methods with same name but it must differ in one of the
follwing:
--> Number of arguments.
--> Datatype of arguments.
--> Order of the arguments.
for ex:
class sample
{
public:
void add (int a, int b)
{
}
void add (int a, int b, int c)
{
}
}
In this case the number of arguments are different so it is
method overloading.
Is This Answer Correct ? | 20 Yes | 3 No |
Answer / manohar
My question is where and what exactly does overloading does.
instead of taking risk we can use different names for
methods right.so,that we do not have any confusion, because
if we have to call overloaded methods from main method then
definetly we have to call every method with different
parameter again which is performance issue. So can you
please provide me the exact answer for this provided
examples if any one has.
Is This Answer Correct ? | 13 Yes | 3 No |
Answer / dev yadav
same class two metheod & different parameters....
Is This Answer Correct ? | 15 Yes | 5 No |
Answer / rajesh bonepalli
Overloading in java means creating the methods by same
method signature(name,return type) passing different
arguments/parameters.
Example :
public class Children {
public void getHabits(int k){
System.out.println("overriding in the children with
childrens behaviour int");
}
public void getHabits(){
System.out.println("overriding in the children with
childrens behaviour");
}
public void getHabits(double j){
System.out.println("overriding in the children with
childrens behaviour double");
}
public String getHabits(double j,double i){
System.out.println("overriding in the children with
childrens behaviour double");
return null;
}
}
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / jephin daviss
Overloading means that the same operator, method maybe used
for different purposes.
It is part of the OOP concept 'Polymorphism'.
1)Method overloading:Methods with same name, but different
argument types and number of arguments.
2)Operator overloading: Same operator can be used for
different ways, ex:'+' can be used for addition and for
concatenation.
3)Constructor overloading: We can define two constructors
for a same class, ie with same name, but difference in
argument types and number of arguments.
Is This Answer Correct ? | 10 Yes | 7 No |
What does mean in regex?
Write the program numbers into words.For example 2345==two thousand three hundred fourty five
How do I find and replace in word?
What is java command?
Tell me the latest versions in java related areas?
When finalize method is called?
What is the type of lambda expression?
Does substring create a new object?
What are namespaces in java?
I was asked to draw the class diagram for the below scenario which should obey OOPS concept. A Portal is to be developed for a school , which has 3 main divisions viz , Education , Admin & Trust. Each division has 2 sub divisions Kinder Garden & Higer Secondary.
What do you mean by mnemonics?
What is Runtime class and its purpose?