Rules for function-overriding

The main advantage of function-overriding is that each class can provide its own implementation to the inherited function without modifying the superclass. This is helpful when a class has more than one derived classes. If a child class wants to replace the parent's class function with its own implementation, it is free to do that as well as use the implementation of the parent class. 

There are few rules of overriding:

  • The function in the parent class must be declared open
  • The function in the child class must use the override keyword
  • The function in the child class must have the same name as in the parent class
  • The function in the child class must have the same parameters as in the parent class
  • To restrict the child class from overriding the function, the function in the parent class must be declared as final
..................Content has been hidden....................

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