What is the use of Operator Overloading?



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

Post New Answer

More OOAD Interview Questions

Write about abstract base classes?

0 Answers  


When do you prefer to use composition than aggregation?

1 Answers   InfoAxon Technologies, Protech,


What is the base type from which all structs inherit directly?

0 Answers  


What is abstract method?

0 Answers  


Explain method overriding.

0 Answers  






Is class an Object? Is object a class?

11 Answers  


What is the difference between abstract & interface?

0 Answers   MindCracker,


Which oops concept is used as reuse mechanism?

0 Answers  


Explain Class Diagram in Detail.

2 Answers   InfoAxon Technologies, Protech,


What is serialization? How do we implement serialization actually?

0 Answers  


What is inheritance in java?

2 Answers  


Explain the usage of encapsulation?

0 Answers  


Categories