Difference between overloading and Overriding. <Giving a
confusing example to test the concept.>
(also asked in PA Consultancy Group,iflex,Value
chain,IBM,CTS,Accenture, Tarang>
Answer Posted / ketan gambhir
Overloading:-in overloading,we can use same name of method
and constructor with different parameters in same class.
For Exa:-
\\Both methods has different declaration and definition.
class A
{
public int same(int a int b)
{
return a+b;
}
public void same()
{
System.out.println("ketan");
}
}
Overriding:-In overriding,we can use same method and
constructor with same parameters in different classes.
For Exp:-
class A
{
public void same()
{
System.out.println("same1");
}
}
class B
{
public void same()
{
System.out.println("ketan");
}
}
Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
What is empty list in java?
What's the base class in java from which all classes are derived?
What is the common usage of serialization?
How garbage collection is done in java?
What is java algorithm?
What is the difference between stringbuffer and stringbuilder class?
How do you define a variable?
What is the difference between the size and capacity of a vector?
How to sort an array from smallest to largest java?
Is treeset sorted in java?
Can an interface extend another interface?
How to sort a collection of custom Objects in Java?
Implementations of set interface?
What is overloading and overriding in java?
Objects or references which of them gets garbage collected?