Inheritance

Exercise: Use the virtual and override keywords

Goal

  1. Create an abstract class named Astrodroid that provides a virtual method called GetSound which returns a string. The default sound should be the words "Beep beep".
  2. Implement a method called 'MakeSound' which writes the result of the GetSound method to the Console followed by a new line.
  3. Create a derived class named R2 that inherits from Astrodroid.
  4. Override the GetSound method on the R2 class so that it returns "Beep bop".
Page 15 of 18