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 shekhawat
Overloading and Overiding are pratical implementation of OOPs Concept.
Overloading:
In Simple words, Same function name but different signature(Parameters)
For Example:
To Add 2 integers Add(int i, int j)
To add two string Add(string i, string j)
Depending on the signature(parameters) of the calling function, respective function would be called. if you pass 2 string parameter second function would be called and if you pass two integer parameter first function would be called.
Overriding(Polyphormism):
Same Function Name, same signature, different functionality.
Example for overriding
Class Shapes { Virtual void Paint() }
Class Circle:Shapes { Override void Paint() }
Class Square:Shapes { Override void Paint() }
Here in the above code we can see that the shapes is class which has a method Paint, which would paint according to the shape of the object each object would implement the paint method differently based on its dimensions.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is use of functional interface in java 8? Explain
What is the difference between this() and super() in java?
Is 0 true or false?
How to display all the prime numbers between 1 and n (n is the number, get the input from user)
What are jee technologies?
Is array passed by reference in java?
What is the difference between and ?
What is application system?
Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?
What is the console in java?
What is a method declaration?
What is integer size in java?
When do we use synchronized blocks and advantages of using synchronized blocks?
Why is it called boolean?
Which method returns the length of a string?