ASP. NET learning notes (4) Inheritance

Source: Internet
Author: User

1. inherited rules
1. You can add new members to a derived class, but cannot remove inherited members;
2. constructor and destructor cannot be inherited. The access method of the members in the base class can only determine whether the derived classes can access them;
3. The new member defined in the derived class has the same name as the inherited member, but is overwritten, not removed;
4. classes can define virtual methods, virtual attributes, and virtual index indicators. The Derived classes are overloaded to achieve polymorphism;
5. A derived class can inherit only one base class, but multiple interfaces can be implemented.

2. Access Base members
1. Use base. Method Name ()
Base cannot be used in static methods


2. Explicit type conversion


3. Hide base class members

Public new void SayHello (){}

Iv. sealing and Methods

Sealed modifier. The modified classes and methods cannot be inherited or reloaded.

V. abstract classes and abstract methods

1. Use abstract Modification
2. abstract classes cannot be instantiated.
3. the abstract method does not execute specific code and must be rewritten in a non-Abstract derived class.
4. Methods in abstract classes are abstract methods.

 


5. If you want to override the implementation method in a non-abstract class but not in the base class, you need to use virtual functions (virtual)

 

Vi. Multi-Inheritance

To implement methods with the same names for multiple interfaces, note the following two points:
1. keywords such as public cannot be added before methods with the same name. The corresponding interface name must be added before each method;

2. A method without a name must be preceded by a "public" identifier
Public void Hello (){}

When creating an instance of a derived class, if you call the implementation of an interface, you must forcibly convert the instance to the corresponding interface type.

 

VII. Inheritance and access modifier



By: dxh_0829
 

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.