Bloomberg LP Interview Question
Financial Software DevelopersGenerally, polymorphism refers to the ability to
appear in many forms
● Polymorphism in a Java program
The ability of a reference variable to change
behavior according to what object instance it is
holding.
No,It is not possible to overload a single operator twice......
I think the this not only applies to operators but overloading in general. There cant be any function which can be overloaded with same signatures. The reason for this is name mangling of functions; same function name and different parameter list are being given different names by compiler and appropriate function is called accordingly. If same function parameters are given then logically it should confuse (and it does) compiler to differentiate between different versions of function.
What Victor said is partly correct. You can definitely have two definitions for overloaded operator. But one of them has to be friend function else compiler would throw an error. Suppose you want to overload + operator twice. First function would add 2 integers and second myclass& and int&. so define one of the operator as friend.
An overloaded operator is like a function call, hence it can be overloaded twice but with different signatures. Its nothing but function overloading!
- sudarshan.fs August 23, 2010