Interfaces in Java (interface)

Source: Internet
Author: User

Java advocates interface-oriented programming rather than class-oriented programming, and personal understanding is about what to do and how to separate it for loose coupling purposes.

The basic data types are divided into four categories: integer, floating point, character type, Boolean type, and eight kinds.

There are three types of reference data: Class, interface, array;

1, the interface is not a class;

2, the interface also has properties and methods, the properties of the interface by default with public static final decoration;

3, the method in the interface by default with public abstract modification, the interface can not contain non-abstract methods;

4, a class can implement the interface, with the Implements keyword implementation, if a class implements an interface, then it must implement all the methods defined in the interface, unless the class is abstract;

5, a class can implement more than one interface, and a class can inherit only one class, Java is a single inheritance, but is multi-implementation;

6, a class must be first to write the inheritance, after writing the implementation;

7, the interface can inherit, between the interface can be multiple inheritance;

-The function of the interface is to compensate for the deficiency of single inheritance;

        

Thinking: What is the difference between an interface and an abstract class:

1, abstract class methods and properties do not have a default modifier,

The interface method is the abstract method by default;

2, abstract classes can have member methods can also have an abstract method,

There can be only abstract methods in the interface (it is said that the interface in JDK 1.8 can have a default implementation, no use);

3, abstract class can only be inherited, and to single inheritance,

Interfaces can be implemented by classes (multiple implementations) and can be inherited by interfaces (multiple inheritance);

Interfaces in Java (interface)

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.