Recommended Answers
Jump to PostSometimes we create complex objects that need special handling when we do things like add them together (or subtract).
http://en.wikipedia.org/wiki/Operator_overloading
Let's say you have a class that has a description and …
Jump to PostIn other words, simplistically, it's a way to define what ==, <, >, etc are meant to be for a class that you define yourself.
Example, you have a class of CAR which contains
Make
Model
Year
PriceYou can define operator= to mean:
Same Make
Same Year
…
Jump to PostConvenience is one benefit.
Jump to PostBut we can do these without overloading also.
Sure. We can make a function:
CAR AddTwoCars(CAR vehicle1, CAR vehicle2, CAR vehicleNew)
which 'adds' #1 & #2 and returns the new one. Or we can overload the + operator and have:vehicleNew = vehicle1 + vehicle2;
Java do not support …
All 13 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.