Using system;
Namespace csharpjichu
{
Public class baseclass
{
Private string a = string. empty;
Public void runatbaseclassa ()
{
Console. writeline ("runatbaseclassa ");
}
Public Virtual void runatbaseclassvirtual ()
{
Console. writeline ("runatbaseclassvirtuala ");
}
}
Public abstract class abstractclassa: baseclass
{
String astr = string. empty;
Public abstract void abstractmethoda ();
Public void abstractclass ()
{
Console. writeline ("runatabstractclassa ");
}
}
Class extend1_actclass: abstractclassa
{
Private string a = string. empty;
Public override void abstractmethoda ()
{
Console. writeline ("runatextendabstractclass ");
}
}
Public abstract class abstractclassb
{
String astr = string. empty;
Internal abstract void abstractmethodb ();
}
class Program
{< br> static void main (string [] ARGs)
{< br> console. writeline ("-------------------- the following is an abstract class test --------------------");
extend1_actclass abc = new extend1_actclass ();
ABC. abstractclass ();
ABC. abstractmethoda ();
console. writeline ("------------------ abstract class can also inherit the base class ----------------------");
console. writeline ("------------------ The following is the abstract class that inherits the baseclass class ----------------------");
console. writeline ("------------------ inherits the method of accessing the baseclass class from the subclass extend1_actclass of the abstract class ----------------------");
ABC. runatbaseclassa ();
ABC. runatbaseclassvirtual ();
console. writeline ("------------------ the above is the abstract class test ----------------------");
console. read ();
}< BR >}
}
Running result:
Summary:
1. The method of the abstract class has no implementation body, and only the declaration is required.
2. abstract classes can contain abstract methods, non-abstract methods, and variables.
3. Classes containing abstract methods must be abstract classes.
4. abstract classes cannot be instantiated.
5. abstract methods cannot be modified using private. Other modifiers can be modified.
6. When the subclass inherits the abstract class, the subclass must override all abstract methods of the abstract class.
7. The abstract class can also inherit the base class. After the abstract class inherits the baseclass class, it inherits the subclass extend1_actclass object of the abstract class to access the method of the baseclass class.
8. When an abstract class inherits the base class, the access modifier of the base class cannot be smaller than the access modifier of the abstract class.