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

What do you mean by operator overloading?

0 Answers   BirlaSoft,


What are a base class, subclass, and superclass?

0 Answers  


Explain the different types of constructors

0 Answers  


How to define an interface?

0 Answers  


What is inheritance?

7 Answers   Protech,






Is it possible to provide method implementations in java interfaces? If possible, how do we provide them?

0 Answers  


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

1 Answers   Protech,


Write basic concepts of oops?

0 Answers  


What is an abstraction and why is it important?

0 Answers  


Why is class hierarchies managed in object-oriented programming?

0 Answers  


Does a class inherit the constructor of its super class?

0 Answers  


How to differentiate between a CreateObject() and GetObject() ?

0 Answers   CGI,


Categories