CHAPTER 12

image

Redefining Members

A member in a derived class can redefine a member in its base class. This can be done for all kinds of inherited members, but it is most often used to give instance methods new implementations. To give a method a new implementation, the method is redefined in the child class with the same signature as it has in the base class. The signature includes the name, parameters and return type of the method.

class Rectangle{   public int x = 1, y = 10;  public int GetArea() { return x * y; }}   class Square : Rectangle{   public int GetArea() { return 2 * x; }} 

Hiding members

It must be specified whether the method is intended ...

Get C# Quick Syntax Reference 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.