Test Your Knowledge: Quiz
Question 12-1. What is operator overloading?
Question 12-2. Are operators implemented as properties, static methods, or instance methods?
Question 12-3. What keyword do you use to overload an operator?
Question 12-4. How does the compiler translate:
Fraction f3 = f2 + f1;
assuming that f2 and f1 are Fraction objects and you have overloaded the + operator for the Fraction class?
Question 12-5. Which of the following overloads are reasonable?
Overloading the
==operator for aDogclass such that twoDogobjects with the same name are equalOverloading the
-operator of aBoxclass such that subtracting oneBoxobject from another produces a newBoxobject with a volume equal to the difference between the other twoBoxobjectsOverloading the
--operator of anEmployeeclass so that the employee’s hours are reducedOverloading the
+operator of aBankAccountclass to merge the balance of two accounts
Question 12-6. Which of the comparison operators are paired?
Question 12-7. What should you also do if you overload the == operator?
Question 12-8. What is the purpose of the Equals() method?
Question 12-9. What keyword(s) do you use to overload the conversion operators?
Question 12-10. When should you use implicit conversion, and when should you use explicit conversion?
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access