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


Please Help Members By Posting Answers For Below Questions

What are static initalizers in java ?

585


How many types of variables are there?

676


What is difference between iterator and enumeration in java?

527


What class allows you to read objects directly from a stream?

876


How many types of equations are there?

544






How do you use spaces in java?

534


How to optimize the javac output?

602


What is string and its types?

614


What does microservices mean?

535


How to invoke external process in java.

574


Can each java object keep track of all the threads that want to exclusively access it?

543


How do you pass by reference?

539


What is final, finally, finalize?

603


Explain the difference between abstract classes and interfaces in java?

602


Where and how can you use a private constructor?

540