Introduction to the difference between Java abstract classes and interfaces _java

Source: Internet
Author: User

The difference between an abstract class and an interface

Abstract class

The class that contains the abstract method is the abstract class, the declared statement: abstract class
Must be public protected

Interface

An abstraction of behavior, declaring statements: interface
Modifiers for abstract methods: Public abstract
Modifiers for member variables: public static final

Grammatical level

  1. Abstract classes can contain implementation details for member methods, and only abstract methods exist in interfaces-public abstract
  2. The member variables in an abstract class can be of various types, and the member variables in the interface can only be public static final
  3. An abstract class can contain static methods and static code blocks that cannot be included in an interface
  4. A class can inherit only one abstract class and implement multiple interfaces
  5. Different access modifiers: the modifiers of the abstract class method are public/protected; The modifiers of the method in the interface must be public

Design level

Abstract classes are abstractions of things, abstractions of classes; interfaces are abstractions of behavior, describing a code of conduct

An abstract class is an abstract description of an entire class, containing attributes and behavior; an interface can only abstract the behavior of a class

Attach a Picture:

Thank you for reading, I hope to help you, thank you for your support for this site!

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.