Static, abstract class, interface, class library, abstract class library

Source: Internet
Author: User

Static, abstract class, interface, class library, abstract class library

1. Common Member
Common members belong to objects.
Call with object

2. Static members
Static members belong to the class
Called by Class Name

Stactic static keywords

Static methods cannot contain common members.
The common method can contain static members.

 

Abstract class:

1. Keywords: abstract
2. abstract classes can contain abstract methods and common methods.
3. abstract keywords can define methods as abstract methods. abstract methods can have no function bodies.
4. abstract classes cannot be instantiated. abstract classes are mainly used as a base class to inherit other classes.
5. The sealed and abstract keywords cannot appear at the same time.
6. If a subclass inherits from an abstract class, all abstract methods must be implemented in the subclass.
7. If the subclass does not implement the abstract method of the parent class, the subclass must be an abstract class.
8. If a class contains abstract methods, the class must be an abstract class.

 

Interface:

An extremely abstract class.

Head Office-rules and regulations (interfaces)-the company must perform attendance on its employees

Subsidiary Company 1-following the rules and regulations of the company-implementing attendance-punching
Subsidiary Company 2-following the rules and regulations of the company-implementing attendance-naming

Differences between interfaces and abstract classes:
1. Differences in writing
Keyword: interface
Class names without class keywords generally start with I
You don't need to write public because it is public and you don't need to write abstract interfaces.
Like

2. The interface cannot contain common members.

3. All classes that inherit interfaces must implement methods in interfaces.

// Class library

Class must be public access permission

A dll file is a class library. It can be used but cannot be modified.

Sometimes we need to use classes written by others

1. If the class is a source code class. cs File
After getting the file to the project, you can choose to add a new item or add an existing item.
Introduce the corresponding namespace

2. If the class is not the source code, but the compiled. dll file (the compiled Class Library)
Get the file to the project, add reference, browse, and find the. dll file.
Introduce the corresponding namespace

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.