Java Interview Basics------"What are the similarities and differences between abstract classes and interfaces?

Source: Internet
Author: User

Key points!!!!

1 , abstract class ( Abstract class ) and Interfaces ( Interface what are the similarities and differences?

same Point

* cannot be instantiated directly , but can be implemented through inheritance to implement its abstract method .
* are the technical basis for abstract programming, and realize a lot of design patterns.

different points

* The interface supports multiple inheritance , and abstract classes cannot implement multiple inheritance .
* interfaces where the abstract methods are all implemented
* Interfaces can only define abstract rules; Abstract classes can define rules and may also provide implemented members.
* An interface is a set of behavior specifications; An abstract class is an incomplete class that focuses on the concept of a family.
* Abstract classes do not necessarily have abstract methods .
* Interfaces only contain signatures for methods, properties, indexers , events, but cannot define fields and methods that contain implementations; Abstract classes can define fields, properties, and methods that contain implementations.
* Interfaces can be used for value types and reference types , and abstract classes can only be used for reference types . For example, a struct can inherit an interface and not inherit a class.
* The members in the interface are all public, and the member variables defined in the interface are actually constants.
* The methods in the interface are abstract methods

Java Interview Basics------"What are the similarities and differences between abstract classes 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.