7.10. Method overriding using the virtual and override Modifiers

There are some significant differences here between Java and C#. Method overriding in C# involves two keywords borrowed from C++ with no equivalents in Java – virtual and override. Take note of them carefully.

Like Java

  • Private methods in the superclass cannot be overridden in a subclass. If a subclass has a method of the same signature as a private method in the superclass, this is not considered to be a method override. [12]

    [12] Take note that if a method is declared as private in the superclass, and there is a method of the same signature (name and parameters only – the method signature excludes the return type) in the subclass, this does not constitute 'method overriding'. The ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.