O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required