What is the use of Operator Overloading?
Answer / ben jacob
Operator Overloading helps users/developers use a particular
class in an intuitive manner for different kind of
operations logically possible on the class.
It's used for ease of code read and maintainability.
e.g. Date 'b' can be subtracted from another instance of
Date, say 'a', to get the difference in number of days
between the two days.
So, you would overload the subtraction operator '-' for the
Date class accordingly.
Date a("07/04/2008);
Date b("05/04/2008);
//operator overoading for '-' for Date
//returns number of days
int Date::operator-(const Date& rhsDate)
{
//wotever logic
return <number of days between the (this) date and rhsDate>
}
Is This Answer Correct ? | 5 Yes | 0 No |
What do you mean by operator overloading?
What are a base class, subclass, and superclass?
Explain the different types of constructors
How to define an interface?
What is inheritance?
Is it possible to provide method implementations in java interfaces? If possible, how do we provide them?
Comment: C++ "includes" behavior and java "imports"
Write basic concepts of oops?
What is an abstraction and why is it important?
Why is class hierarchies managed in object-oriented programming?
Does a class inherit the constructor of its super class?
How to differentiate between a CreateObject() and GetObject() ?