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]
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 void Main(){ 13: MyClass mc = new MyClass(); 14: Console.WriteLine(mc.DoSomething()); 15: } 16: } Like Java
|