Interface interface_ polymorphism

interface

Five kinds of interface members

1, JDK7 later version

    常量 public static final String name= "laohuo";

    Abstract methods public abstract void methodAbstract ();

After 2, JDK8 version

    The default method of public default void methodDefault () {}

    Static method public static void methodStatic () {}

3, JDK9 later version

    Private methods private void methodPrivate () {}

Notes interface

A. multiple interfaces, abstract methods conflict. Subclasses overwritten only an abstract method

B. multiple interfaces, the default method of conflict. The subclass must override the default method of conflict rewrite

C. common method of parent class and the default interface method among conflict. Priority class using common methods of the parent 

Categories and classes: inheritance "single inheritance, multi-level inheritance"

Interface and Interface: inheritance "multiple inheritance"

Classes and interfaces: realization relationship "and more to achieve"

Polymorphism

Polymorphic prerequisite (three)

A. Relationship inheritance (class inheritance, interface)
       covered a method of rewriting B.
       C. parent subclass object // references to left and right child parent Fu obj = new Zi ();

Features multi-state members

Member variable: "Look at the left side of the equal sign is who, who use it a priority, then there is no looking up"

Member method: "Look to the right of the equal sign, who is new, who use it a priority, then there is no looking up"

Transition object (like a similar implicit type conversion and casts)

Upward transition (can be automatically converted)

Downward transition (cast) may be converted to solve problems using instanceof whether the object is a class

发布了12 篇原创文章 · 获赞 0 · 访问量 179

Guess you like

Origin blog.csdn.net/qq_45068627/article/details/104338339