what is overloading and overriding with example?
Answers were Sorted based on User's Feedback
Answer / sujanya
Overloading means two methods have the same method name and
different argument list.
For example, take the case of a Shape Class where you have
a method with the name DrawShape();
This method has two definitins with different parameters.
1. public void DrawShape(int x1, int y1,int x2,int y2)
{
// draw a rectangle.
}
2. public void DrawShape(int x1,int y1)
{
// draw aline.
}
overriding means i have a super class and sub class,sub
class extends the super class.Two classes containg the same
method name and same arguments sub class overides the super
class method ,this is nothing but method overriding
for example
Class Rectangle
{
publc void DrawRectangle()
{
// this method will draw a rectangle.
}
}
Class RoundRectangle : Rectanlge
{
public void DrawRectangle()
{
//Here the DrawRectangle() method is overridden in the
// derived class to draw a specific implementation to the
//derived class, i.e to draw a rectangle with rounded
corner.
}
}
| Is This Answer Correct ? | 48 Yes | 16 No |
Answer / rajesh r
OVERLOADING MEANS SAME METHOD NAME WITH DIFFERENT
PARAMETERS.
BOTH SHOULD BE DEFINED IN SAME CLASS ITSELF.
OVERRIDING MEANS SAME METHOD NAME WITH SAME PARAMETERS.THIS
CAN ASSOCIATED IN A CLASS AND ITS SUBCLASS.(VIRTUAL,
OVERRIDE)
| Is This Answer Correct ? | 4 Yes | 0 No |
What is string made of?
what is difference between set and list in collection?
What is Java Reflection API? Why it’s so important to have?
What are the concepts of 'OOPS'?
What does java stand for?
How do you sort an array in java?
How to print nodes of a Binary tree?
What is an empty class? What functionality does it offer in Java?
0 Answers Deloitte, EXL, JPMorgan Chase,
when i write string s1="java"; in one program(application) and string s2="java"; in another application on the same jvm will both objects s2,s2 will refer to same memory location where "java" is stored in string pool.
Define Wrapper Classes in Java.
What does g mean in regex?
Is it compulsory to have atleast one abstract method in abstract class?