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?

  1. Overloading the == operator for a Dog class such that two Dog objects with the same name are equal

  2. Overloading the - operator of a Box class such that subtracting one Box object from another produces a new Box object with a volume equal to the difference between the other two Box objects

  3. Overloading the -- operator of an Employee class so that the employee’s hours are reduced

  4. Overloading the + operator of a BankAccount 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?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset