December 2001
Intermediate to advanced
416 pages
8h 16m
English
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 ...
Read now
Unlock full access