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

6.8. Abstract classes

The idea of abstract classes in C# is pretty much identical to that in Java – a class which cannot be instantiated, and which may contain abstract methods.

There follows an example of an abstract class, MyAbstractClass, which contains one abstract method, DoSomething(). MyClass inherits from MyAbstractClass and provides an implementation of the method. [14]

[14] On line 8, the override modifier is used to declare that DoSomething() is overriding the abstract method of the same name in the superclass.

 1: using System;
 2:
 3: public abstract class MyAbstractClass{
 4:   public abstract int DoSomething();
 5: }
 6:
 7: public class MyClass:MyAbstractClass{
 8:   public override int DoSomething(){ 9: return 0; 10: } 11: 12: public static ...

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