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>

Answers were Sorted based on User's Feedback



Difference between overloading and Overriding. <Giving a confusing example to test the concept...

Answer / 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

Difference between overloading and Overriding. <Giving a confusing example to test the concept...

Answer / ganga

using same methodname with different signatures is known as
overloading where as
changing the definition of the parentclass in chidclass is
known as overridding.

Is This Answer Correct ?    7 Yes 9 No

Post New Answer

More Core Java Interview Questions

What is a hashmap used for?

0 Answers  


How do you test a method for an exception using junit?

0 Answers  


what is platform independence in java?

5 Answers   CSC, HSBC,


What does flagged out mean?

0 Answers  


Is null == null in java?

0 Answers  






What access modifiers can be used for class ?

0 Answers  


In Java list the methods that can be overridden?

0 Answers   Accenture,


What is compile time polymorphism?

20 Answers   CTS, Elementus Technologies, Oracle,


What is the covariant return type?

0 Answers  


Explain illegalmonitorstateexception and when it will be thrown?

0 Answers  


What is jvm? Why is java called the platform independent programming language?

0 Answers  


What is the difference between stored procedure & function?

0 Answers  


Categories