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


Please Help Members By Posting Answers For Below Questions

What is empty list in java?

828


What's the base class in java from which all classes are derived?

1010


What is the common usage of serialization?

808


How garbage collection is done in java?

777


What is java algorithm?

707


What is the difference between stringbuffer and stringbuilder class?

805


How do you define a variable?

731


What is the difference between the size and capacity of a vector?

788


How to sort an array from smallest to largest java?

779


Is treeset sorted in java?

768


Can an interface extend another interface?

817


How to sort a collection of custom Objects in Java?

826


Implementations of set interface?

771


What is overloading and overriding in java?

914


Objects or references which of them gets garbage collected?

730