Differences between interfaces and abstract classes-Interview Questions

Source: Internet
Author: User

Java provides and supports creating abstract classes and interfaces. Their implementations share the following things:

  • All methods in the interface are implicitly abstract. Abstract classes can contain both abstract and non-abstract methods.

  • Class can implement many interfaces, but can inherit only one abstract class

  • Class to implement an interface, it must implement all methods declared by the interface. However, classes do not implement all methods declared in abstract classes. In this case, classes must be declared abstract.

  • Abstract classes can implement interfaces without interface methods.

  • The variables declared in the Java interface are final by default. Abstract classes can contain non-final variables.

  • The member functions in the Java interface are public by default. Abstract class member functions can be private, protected, or public.

  • Interfaces are absolutely abstract and cannot be instantiated. Abstract classes cannot be instantiated, but can be called if they contain the main method.

Differences between interfaces and abstract classes-Interview Questions

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.