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

Giving reasons explain two external responsibilities of a project manager.

2 Answers  


Describe the Diamond problem. Where does this problem occur?

0 Answers   Tech Mahindra,


Explain about the relationship between object oriented programming and databases?

0 Answers  


Explain Class Diagram in Detail.

2 Answers   InfoAxon Technologies, Protech,


What is diamond inheritance problem? How java 8 solves this problem?

0 Answers  


State two differences between an object and a class.

0 Answers   DELL,


How many methods do u implement if implement the serializable interface?

0 Answers  


Differences between functional programming and object-oriented programming?

0 Answers  


Can you give some examples of tokens?

0 Answers  


Comment: C++ "includes" behavior and java "imports"

1 Answers   Protech,


Can you create an instance of an interface?

0 Answers  


Explain the implementation phase with respect to oop?

0 Answers  


Categories