Every object has a toString method inherited from the Object class it extends, which can be overloaded. IS there a way to do a similar thing with objects? Here is what I want to do: int a=n+1; where n is actually an object, but when used as an int has a specific value (eg. specified in the constructor).
This is called operator overloading. You cannot do it in Java. And it is disallowed by design as far as I'm aware. I guess you're coming from C++ or C#, where this is possible.
http://en.wikipedia.org/wiki/Operator_overloading
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With