Abstract modifiers can be used with classes, methods, attributes, indexers, and events. Abstract modifier in the class declaration to indicate that a class can only be the base class of other classes. Members marked as abstract or included in an abstract class must be implemented through classes derived from the abstract class.
Abstract classes have the following features: abstract classes cannot be instantiated; abstract classes can contain abstract methods and abstract accessors; abstract classes cannot be modified using the sealed modifier, because sealed will make the abstract classes unable to be inherited; A non-abstract class derived from an abstract class must include all the inherited abstract methods and the actual implementation of the abstract accessors.
Use the abstract modifier in a method or attribute declaration to indicate that a method or attribute does not contain an implementation. Abstract methods have the following features: abstract methods are implicit virtual methods. They can only be declared using abstract methods in abstract classes. Because abstract method declarations do not provide actual implementation, there is no method body, the method ends with a semicolon and there is no braces ({}) after the signature. This method is provided by override, which is a non-abstract class member; it is incorrect to use the static or virtual modifier in the abstract method declaration.
// The abstract class cannot be sealed or static. // abstract sealed class TestClass {}// abstract static class TestClass {}
Abstract class BaseClass {protected int _ x = 100; protected int _ y = 150; public abstract void AbstractMethod (); public abstract int X {get ;} public abstract int Y {get;} // static members cannot be marked as abstract/public static abstract void StaticMethod ();} class DerivedClass: BaseClass {public override void AbstractMethod () {_ x ++; _ y ++;} public override int X {get {return _ x + 10 ;}} public override int Y {get {return _ y + 10;} public static void Main () {DerivedClass c = new DerivedClass (); c. abstractMethod (); Console. writeLine ("x = {0}, y = {1}", c. x, c. y); Console. writeLine (); Console. writeLine ("Press Enter to close this window. "); Console. readLine ();}}