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.9. Abstract methods

Abstract methods in C# are pretty much the same as abstract methods in Java, except for some additional rules. Here is an example.

1: abstract class A{
2:   protected abstract int ProcessInt(int i);
3: }
4:
5: class B:A{
6:   protected override int ProcessInt(int i){
7:     return i*2;
8:   }
9: }

Like Java

  • No implementation of that method is provided – overriding methods of non-abstract subclasses are expected to provide the method implementation.

  • Abstract methods cannot be private. [10]

    [10] Abstract private methods don't make sense at all since abstract methods are intended to be overridden, and private methods cannot be overridden in subclasses.

  • Classes with one or more abstract methods must be declared as an abstract class (although ...

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