The relationship between the Java interfaces and classes and interfaces

The relationship between the interface and the interface

Inheritance

Can multiple inheritance and multiple layers can inherit

note:

1. If more than one parent interface has the same name as the abstract method , then the sub-interface need only realize once

2. If more than one parent interface has the same name as the default method , then the sub-interface must override the default method, we must add the default keyword 3. If more than one parent interface has the same name as a static method , then disregarded, because the static method only for interface

4. If a plurality of parent interfaces have the same name private methods , so disregarded, because this method can only private interface

 

The relationship between interfaces and classes

Realization relationship

Single implement: a class implements only one interface

Multi implement: a class can implement multiple interfaces simultaneously

format:

public  class name of the class implements the interface names 1, 2 interface name, {... 

}

note:

1. If a plurality of interfaces of the same name in the abstract method , then the implementation class only needs to achieve a

2. If multiple interfaces have the same name as the default method , the implementation class must be rewritten once, and you want to remove the default keyword

3. If multiple interfaces have the same name as a static method , then the implementation class disregarded interface static method is for direct use interfaces

4. If a plurality of interfaces of the same name in private methods , the implementation class disregarded, because the interface private methods can only be used in the present interface

The default method sub-interface override the parent interface, you must add the default keyword

Override the default implementation class interface methods, you must remove the default keyword

 

A class inherits from another class either, multiple interfaces may also be implemented

format:

public  class name of the class extends the parent class name implements interface name 1, interface name 2, ... {
    
}

note:

1. If the interface , and the parent class has the default method of the same name , priority call parent class default method

2. If there are interfaces and abstract methods of the same name in the parent class, then a subclass must override abstract methods

 

Ordinary class, abstract classes and interfaces

Common categories: member variables, constructors, methods members, static code block

Abstract class: member variables, constructors, member methods, static code block, abstract method ---> can not directly create objects

Interface:   Constant, the default methods, static methods, private methods, abstract methods ---> can not directly create objects

 

Interface as parameters the method, the object can receive all the interface implementation class

Object interface as the return value of the method can return all the interface implementation class

Guess you like

Origin www.cnblogs.com/libinhong/p/10990476.html