The differences between abstract classes, virtual methods, and interfaces

Source: Internet
Author: User

Interface

1. The interface only provides the method specification, does not provide the method body;

2. The methods in the interface cannot be decorated with keywords;

3. Interfaces and variables cannot be in the interface;

4. The method in the interface must be fully implemented in the subclass;

5. The interface can achieve multiple inheritance;

Abstract class

1. Abstract classes can be inherited from interfaces;

2. Entity methods in abstract classes cannot be overridden in subclasses and can only be referenced;

3. Abstract methods in abstract classes may not have method bodies, abstract methods in abstract classes must be rewritten in subclasses;

4. Virtual methods in abstract classes can be selectively overridden in subclasses;

Virtual method

1. Can be overridden in sub-class selectively;

2. Do not rewrite can also be called quilt class;

The similarities and differences between interfaces and abstract classes

1. Abstract methods and methods within an interface must all be implemented in subclasses;

2. Methods in both abstract methods and interfaces can not have method bodies;

The similarities and differences between abstract method and virtual method

1. The class in which the abstract method resides must be an abstract class, and virtual methods can be in any class;

2. Abstract methods must be rewritten, and the rewriting of virtual methods is selective;

3. Abstract methods can not be called by the quilt class, virtual methods can be called by the quilt class;

4. Abstract methods can not have method body, virtual method must have method body

The differences between abstract classes, virtual methods, and 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.