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 aDog
class such that twoDog
objects with the same name are equalOverloading the
-
operator of aBox
class such that subtracting oneBox
object from another produces a newBox
object with a volume equal to the difference between the other twoBox
objectsOverloading the
--
operator of anEmployee
class so that the employee’s hours are reducedOverloading the
+
operator of aBankAccount
class 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?
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.