Programmer's first year ---- virtual method and abstract method (study notes)

Source: Internet
Author: User

In C # learning, it is easy to confuse the use of virtual and abstract methods. Now let's discuss the differences between them. Both of them involve the use of override in a derived class.

1. Virtual Method)

Virtual keywords are used to modify methods in the base class. Virtual instances can be used in two scenarios:

Case 1: The virtual method is defined in the base class, but the virtual method is not overwritten in the derived class. In the call to a derived class instance, the virtual method uses the method defined by the base class.

Case 2: The virtual method is defined in the base class, and then override is used in the derived class to override the method. In the call to a derived class instance, this virtual method uses a derived override method.

Ii. abstract Method)

Abstract keywords can only be usedAbstract classAnd there is no specific implementation. Abstract methods must be implemented using the override keyword in the derived class.

 

 

Http://www.5ufanli.net

In C # learning, it is easy to confuse the use of virtual and abstract methods. Now let's discuss the differences between them. Both of them involve the use of override in a derived class.

1. Virtual Method)

Virtual keywords are used to modify methods in the base class. Virtual instances can be used in two scenarios:

Case 1: The virtual method is defined in the base class, but the virtual method is not overwritten in the derived class. In the call to a derived class instance, the virtual method uses the method defined by the base class.

Case 2: The virtual method is defined in the base class, and then override is used in the derived class to override the method. In the call to a derived class instance, this virtual method uses a derived override method.

Ii. abstract Method)

Abstract keywords can only be usedAbstract classAnd there is no specific implementation. Abstract methods must be implemented using the override keyword in the derived class.

 

 

Http://www.5ufanli.net

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.