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 is a concrete classes? Is Java object class is concrete class?

770


When do we use hashset over treeset?

802


What is runtime locatable code?

1158


can java object be locked down for exclusive use by a given thread? : Java thread

813


Can java inner class be static?

780


What is keyword in oop?

780


Tell some latest versions in JAVA related areas?

793


What is regex in java?

737


What modifiers may be used with an inner class that is a member of an outer class in java programming?

797


Define iterator and methods in iterator?

771


What is type conversion in java?

824


what are the methods in object?

917


Explain inner classes ?

911


Is upper case in java?

764


how come we know the object is no more used in the class?

6042