4.6. Overloaded, Hidden, or Ambiguous?

Consider the following class hierarchy:

class Base
{
  public void f( int ival ){ ... }
}

class Derived : Base
{
      public void f( ref int ix ){ ... }
}

Does the definition of f() within the Derived class require a new specifier? Or, to put it in program terms, which of the following invocations, if any, result in a compile-time error?

public static void main()
{
   Derived d = new Derived;
   int ival = 1024;

   d.f( ref ival ); // OK?
   d.f( ival );     // OK?
}

The answers are (1) no, the new specifier is not required, and (2) none of the invocations result in a compile-time error. That is, the definition of f() within the Derived class does not hide the base-class instance. Within the Derived class, both instances are ...

Get C# Primer: A Practical Approach 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.