Virtual Methods, polymorphism, Abstract methods and Interfaces

Source: Internet
Author: User
Virtual Method

1. The virtual methods in the parent class are implemented by default.

2. Subclass can override the virtual method override of the parent class

 

LSP)

The parent class variable points to the subclass object.

 

Abstract Method

1. No method body

2. It must be in the abstract class

3. The subclass must override the abstract method unless the subclass is also an abstract class.

4. the abstract class cannot be instantiated.

5. The access modifier of the abstract member cannot be private.

6. Subclass cannot use the base keyword to call the abstract method of the parent class.

Interface:

1. The interface is a special abstract class.

2. Attribute method indexer time

3. Access modifiers cannot be added to interface members.

4. The class of the current interface must implement all the members of the interface, but can be implemented as virtual or abstract methods.

5. Classes are single-inherited but can be implemented in multiple ways

6. abstract classes emphasize the concept of a family. interfaces are completely a constraint that standardizes the behavior of classes. 7. interfaces can inherit more. 8. Avoid interface contamination when defining interfaces.

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.