Java abstraction and interfaces

Source: Internet
Author: User

 

====================== Abstract =============================

Abstract concepts

  1. An abstract class cannot be directly instantiated. Only its non-Abstract subclass can be instantiated.
  2. Abstract classes do not necessarily contain abstract methods. abstract methods must be in abstract classes.
  3. Abstract METHODS only have method headers and no method bodies.
  4. Constructor methods and class methods (static-modified methods) cannot be declared as abstract methods.
  5. The subclass of an abstract class must provide the specific implementation of all methods of the abstract class, unless the subclass is also an abstract class.
  6. Abstract cannot be used with private/static/FINAL.

Abstract meaning

Unified interface for defining implementation methods

====================

Interface

====================
Interface Concept

A set of methods and variables, all composed of abstract methods, modified with implements, is called an interface.

Note:

  1. A class can implement multiple interfaces. To implement an interface class, you must override all member methods in the interface.
  2. All the variables in the interface are final static variables. (Final, static)
  3. You cannot create an instance because the interface does not have a constructor.
  4. The interface is not a class and may be a bit absolute, but it can be said that it is not a class derived from class.
======================

Differences between an abstract class and an interface ========================

  1. The interface is defined by interfaces. The abstract class is class;
  2. Methods In interfaces are abstract methods. Methods in abstract classes may or may not exist;
  3. The interface adopts the multi-Inheritance Mechanism, and the abstract class adopts a single Inheritance Mechanism;
  4. An abstract class represents an inheritance relationship, and an interface represents a function. The two are used to understand the problem domain.

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.