Java-based interface

Source: Internet
Author: User

After you know the abstract class, look at the interface.

In Java, the content of an interface is primarily an abstract method, and of course it can contain properties (the properties defined in the interface are only constants by default): In general, the properties are not defined in the interface:

The interface keyword interface is a simple interface.

Defines an interface inter, which has a method show. Obviously, the method in the interface is also abstract, so we need to implement it.

How to implement the interface: implements.

Interfaces are used in the same way as abstract classes. Here we do not discuss the difference between the interface and the abstract class, left to the next talk

Considerations for the interface:

1. Interface, we can understand that it is a set of rules in Java, and the rules are fixed, and should not be changed.

2. According to 1, the attribute (variable) should be a constant

3. Only public abstract methods are allowed to exist in the interface. (void show () = public abstract void show) public abstract can be omitted

The advantages of the interface in fact, I think one thing: improve the expansion of the program.

Extensibility: USB jack on the computer. This is the interface, we can use this USB port to expand a variety of devices (audio, cell phones, etc.). The interface in the program you can use as a USB jack for your computer, as well as to expand new content.

It is also important to remember that the principle of interface is to prohibit modification, promote the expansion

Java-based 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.