O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

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

7.11. Method hiding with the new keyword

Please make sure that you understand section 7.10 before you read this section.

Name hiding in C# will be a new concept to Java developers. In C#, the new keyword can be used for two purposes, the first of which is well understood:

  • as an operator – to create a new instance of a class or struct;

  • as a modifier – to create a new class member (method, field, constant, property, type) which hides an inherited member from a superclass.

I will concentrate on the second use in this section.

You can use the new keyword to hide a class member. In this case, we shall be concentrating on method hiding (hence the name of this section). However, the same idea can be applied to other class members (property hiding, field ...

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