Links

1. C# language ref

2. msdn bloggers

3. C# tutorials

How does method inheritance work in c#: virtual override

This article will address the following

Overloading
virtual and overriding
hiding
return types

The plot seems thicker than what the subject seem to indicate

new
virtual
override

use virtual on the base method and override on the derived

use abstract modifier if the method carries no body

changing a base signature will result in incorrect java behavior

Indicate "virtual" explicitly in c#

overloading is when a method has multiple signatures in the same class

for override to work the methods should have the same signature

that may not be the case for hiding

methods are overridden on a signature by signature basis

Here is a good document on java to cover these topics

If, for example, a class declares two public methods with the same name, and a subclass overrides one of them, the subclass still inherits the other method. In this respect, the Java programming language differs from C++.

class Point {
	int x = 0, y = 0;
	void move(int dx, int dy) { x += dx; y += dy; }
	int color;
}
class RealPoint extends Point {
	float x = 0.0f, y = 0.0f;
	void move(int dx, int dy) { move((float)dx, (float)dy); }
	void move(float dx, float dy) { x += dx; y += dy; }
}


a return type doesnt seem to be part of a method signature

it is a compile time error to override a method that differs only in its return type

signature does not include a return type

You can not have two methods that differ only in their return types

A method introduced in a class or struct hides all non-method base class members with the same name, and all base class methods with the same signature (method name and parameter count, modifiers, and types)

You can not have two methods with different return types even the return types substitutable

In c# you can have different return types for the same method if they are derived

    public class TestBase
    {
        public void f1(String a) { Console.WriteLine("tbf1"); }
        public object f2(String a) 
        { 
            Console.WriteLine("tbf2");
            return null;
        }
        public String f2(String a)// error: different return types
        {
            Console.WriteLine("tbf2s");
            return null;
        }
    }
    public class TestDerived : TestBase
    {
        new public void f1(String a) 
        { 
            Console.WriteLine("tdf1");
        }
        public String f2(String a)
        {
            Console.WriteLine("tdf2");
            return null;
        }
    }
    public class TestBase
    {
        //parameter overloading in same class
        public void f_overloading() { Console.WriteLine("tbf1"); }
        public void f_overloading(String a) { Console.WriteLine("tbf1"); }
        public String f_overloading(int i) { return ""; } //ok: different signature
        //public String f_overloading(); //error: different return types with same params
        // '-' character is not allowed

        //different return type allowed in a derived class
        //it will be considered a new hidden method
        public object f_differentReturntype(String a)
        {
            return null;
        }
        //overload across derived
        public void f_overloading_derived()
        {
        }
        
        //virtual method
        public virtual void f_virtual() { }
        //error: different return types even of the same base type
        public virtual object f_virtual_different_returntypes() { return null; }
    }
    public class TestDerived : TestBase
    {
        //different return type allowed in a base class
        //warning: use new to fix it for hiding
        public String f_differentReturntype(String a)
        {
            return null;
        }

        //overload across derived
        //ok
        //same name different signatures
        public void f_overloading_derived(String a){}

        //virtual method
        public override void f_virtual() { }
        //error: different return types even of the same base type
        public override String f_virtual_different_returntypes() { return null; }

    }

From Brad