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

Why abstraction is important?

0 Answers  


Name the different creational patterns in object oriented design?

0 Answers  


What is the difference between data hiding and implementation?

0 Answers  


Is it possible to override private virtual methods?

0 Answers   Infosys,


Explain what is single and multiple inheritance?

0 Answers  






Why is C not an OOP language?

0 Answers   Agilent, Integreon, ZS Associates,


Can I implement polymorphism using abstract class?

0 Answers   MCN Solutions,


Can we have a default method definition in the interface without specifying the keyword "default"?

0 Answers  


What is method overriding?

0 Answers  


Why dynamic loading is used in object-oriented programming?

0 Answers  


What is a functional interface? What is sam interface?

0 Answers  


What are abstract functions? Why are they used?

0 Answers  


Categories