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
Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.
Give us the name of the list layoutmanagers in java?
What is a parameter used for?
Is oracle charging for java?
What is the full name of java?
Write a function for palindrome and factorial and explain?
when should you use stringbuilder class in a program?
Why is it called buffering?
Is main a function?
Why is java so important?
Can we call the run() method instead of start()?
When should you make a function static?
Is java hard to learn?
What is the use of default method in interface in java? Explain
What is thread synchronization in java?