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
Why are constructors used?
Can we create a constructor in abstract class?
What is the use of toarray () in java?
Difference between string, string builder, and string buffer?
Define array. Tell me about 2-D array.
If a method is declared as protected, where may the method be accessed in java programming?
What is the generic class?
What ide should I use for java?
Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me
What is the use of StringTokenizer class?
What is == in java?
Why use string handling in Java?
Explain the difference between abstract class and interface in java?
What are pass by reference and pass by value?
Are global variables initialized to zero?