Java from small white to getting started, Day9. Javaoo-interface

Source: Internet
Author: User

Interface: Make up a single principle that subclasses inherit from a parent class, allowing classes that have no inheritance relationships to share behavior.

The Java interface itself has no implementation, because the Java interface does not involve appearances, but only describes the public behavior, so the Java interface is more abstract than the Java abstract class. But an interface is not a class, and an interface cannot be instantiated with the new operator

Interface keyword: Used to define an interface.

Interfaces: Defining properties: public static constants;

Definition method: Public, abstract method;

Use interface: 1, let subclass to implement interface, implements keyword, implement. All the abstract methods of an interface must be implemented, unless the implementation class is an abstract class.

2, the interface can inherit the interface. Extends a method that has a parent interface for the child interface.

An interface property can only be a static constant that is exposed. Methods can only be public abstract methods, and cannot have constructors.

Design interface Principle: interface Isolation principle (minimum interface principle), and do not cause the upper interface to pollute the lower interface.

Innate behavior, designed as a class.

The behavior of the attached add, designed as an interface.

interface and dynamic binding, the reference to the interface can point to the object of the real class.

Java from small white to getting started, Day9. Javaoo-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.