Abstract class 1

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.