Abstract SDK:

Source: Internet
Author: User

Abstract modifier is used to indicate that the modified class is incomplete and can only be used as the base class. Abstract classes and non-abstract classes are different in the following aspects:
Abstract classes cannot be directly instantiated, and the use of the new operator for abstract classes is a compilation error. Although some types of variables and values during compilation can be abstract, such variables and values must be null, or a reference to an instance that contains a non-abstract class (this non-abstract class is derived from the abstract class ).
Allowed (but not required) abstract classes include abstract members.
Abstract classes cannot be sealed.
When a non-abstract class is derived from an abstract class, these non-abstract classes must specifically implement all the abstract members inherited to override those abstract members.
In the following example
Abstract Class
{
Public abstract void F ();
}
Abstract class B:
{
Public void g (){}
}
Class C: B
{
Public override void F (){
// Actual implementation of F
}
}
Abstract class A introduces abstract method F. Class B introduces another method G, but because it does not provide the Implementation of F, B must also be declared as an abstract class. Class C overrides F and provides a specific implementation. Since C does not have abstract members, you can (but not must) Declare C as a non-abstract class.

Similar to a non-abstract class, an abstract class must also provide its own implementation for all the members of the interface listed in the base class list of this class. However, the abstract class is allowed to map interface methods to abstract methods. For example

Interface imethods
{
Void F ();
Void g ();
}
Abstract class C: imethods
{
Public abstract void F ();
Public abstract void g ();
}
Here, the implementation of imethods maps F and G to abstract methods, which must be rewritten in a non-abstract class derived from C.

Note: explicit interface member implementations cannot be abstract, but explicit interface members are allowed to call abstract methods. For example

Interface imethods
{
Void F ();
Void g ();
}
Abstract class C: imethods
{
Void imethods. F () {ff ();}
Void imethods. G () {Gg ();}
Protected abstract void ff ();
Protected abstract void Gg ();
}
Here, the non-abstract classes derived from C are required to rewrite ff and GG to provide the actual implementation of imethods.

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.