0

Why we use method overriding and method overloading in there any such use of them can anyone explain

2nd Jul 2017, 5:31 PM
Jayram
Jayram - avatar
2 Réponses
+ 1
look at this: 5 * 10 = 50 10 / 2 = 5 Pretty straightforward right? You can easily do this in any programming language whit little effort and achieve the same results... but it is really not that simple in a computer! look at this example: 3 / 2 = 1 3.0 / 2 = 1.5 Notice that even though I haven't changed the operator (/), I get different results? This is because the division operator behaves differently depending on which data types you provide. first case is integer division, the other is float division. This is an example of method overloading, in which the same method can behave differently according to what data you provide. Now, suppose you are writing a simple object called vectors, and you want to add two vectors. It would be so nice to be able to simply write this: [ 5 ] [ 1 ] [ 6 ] [ 7 ] + [ 2 ] = [ 9 ] But the computer doesn't actually know what the addition operator (+) means in this context. For it to work you have to overwrite it's behaviour and specify your own.
2nd Jul 2017, 7:21 PM
Alejandro Aristizabal
Alejandro Aristizabal - avatar
0
Thank u Sir
4th Jul 2017, 4:26 AM
Jayram
Jayram - avatar