+ 5
It is telling operators how they shoul behave. Imagine you have 2 objects: A = {name='John', age=22} B = {name='Jack', age=42} You want to add them together: C = A + B But what does that + mean? Should it create C = {name='JohnJack', age=64} or what? So you can say "hey, operator +, if I use you for this kind of objects, add just ages and let the name be SomeName". This is just one option, you can tell operator whatever you want. Now it is clear that A + B = {name = 'SomeName', age = 64}
9th Dec 2017, 12:17 PM
Daniel Oravec
Daniel Oravec - avatar
+ 1
Making a single operator do different tasks when different data is given as operands....+ is a good example for operator overloading.... ex 1:. int c='a'+'b'; this gives ASCII values of a and b added ie., 193 will be output.... ex 2: String c="a"+"b"; here + concatenates the two strings "a" and "b" and output will be "ab".....ex 3: c=5+6; 11 will be output...so same operator + is doing different operations for different types of data
7th Jan 2018, 1:06 AM
srividya