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
How do you create a method in java?
What does nullpointerexception mean?
What is boolean false?
what is interface in java? Explain
This abstract class is correct ? abstract class A { public abstract void Disp(); public abstract void B() { } public absract virtual C() { } }
Difference between stack and queue?
Can java run on google chrome?
What is sortedmap in java?
What is use of set in java?
What is a boolean expression in java?
How do you invoke a method?
Why are the methods of the math class static?
what is the purpose of the runtime class?
What do you mean by collectors in java 8?
How do you define a method?