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
Can an interface extend a class?
Explain about abstract classes in java?
Can we declare a static variable inside a method?
What is the concatenation operator in java?
Explain static nested classes ?
Is call by reference possible in java?
In how many ways we can create threads in java?
Write a program based on Java script program.
Name few "optional" classes introduced with java 8 ?
What is a variable analysis?
Do you need to import math in java?
why Interface used?
How many types of methods are there?
how can you catch multiple exceptions in java?
What is bytecode verifier?