Interface, abstract class, and virtual Method Analysis

Source: Internet
Author: User

Interface
1. interfaces only provide method conventions, but do not provide method bodies;
2. Methods in the interface cannot be modified with keywords;
3. interfaces and variables cannot exist in interfaces;
4. All methods in the interface must be implemented in the subclass;
5. The interface can implement multiple inheritance;
Abstract class
1. abstract classes can be inherited from interfaces;
2. entity methods in abstract classes cannot be rewritten in subclasses, but can only be referenced;
3. abstract methods in abstract classes cannot have method bodies. abstract methods in abstract classes must be overwritten in subclasses;
4. The virtual methods in the abstract class can be selectively rewritten in the subclass;
Virtual Method
1. It can be selectively rewritten in the subclass;
2. It can also be called by the quilt class without rewriting;
Similarities and differences between interfaces and abstract classes
1. abstract class abstract methods and methods in the interface must all be implemented in the subclass;
2. Methods in abstract methods and interfaces cannot have method bodies;
Similarities and differences between abstract and Virtual Methods
1. The class of the abstract method must be an abstract class, and the virtual method can be in any class;
2. abstract methods must be overwritten, and virtual method rewriting is optional;
3. abstract methods cannot be called by the quilt class. Virtual methods can be called by the quilt class;
4. Abstract METHODS cannot have method bodies. Virtual methods must have method bodies;

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.