# Shiqianfeng against the war classes, JavaEE # Interface

Definition of the interface:
the interface from the point of view like a special syntax abstract class, an abstract method may include both and can not create object.
Interface is a standard, commonly used to constrain subclasses (implementation class) should have the function.
Why Interface?
Coupled between programs can be reduced, more natural polymorphic.
You can use standard interfaces defined in the design aspects of the development of more flexible.
Interface How to define?
Use interface keyword defines an interface:
Syntax: interface interface name {}
interface methods, properties What are the characteristics?
Interface attributes are constant public static implicit use public static final modification.
The method disclosed in the abstract interface are methods, using public abstract implicit modification.
Similarities and Differences abstract classes and interfaces:
the same: 1 can be compiled into byte code file.
2. not create object.
3. can be used as a reference type.
4. With the method in object has.
Different: 1. All properties are public static constants. public static final modification
2. All methods are public abstract methods. public abstract modification
3. No constructor, dynamic, static code block.
Interface Specification
1: ordinary class, a class can only inherit; but can implement multiple interfaces;
2: implement multiple interfaces, all interfaces inside all the abstract methods in this class must be rewritten;
3. We rewrite a method, modifier must be written before the proportion of high levels of access to or the same
4. The method of implementation of the interface, the modifier must be public; [all abstract methods which interfaces, are the default public modifier]
interface polymorphic
declare an interface implementation class to instantiate he
it = new Iinterface ();

对于称呼的纠正;
某个类实现了某个接口;   实现类 -> 父接口;
某个类继承了一个类;    子类(基类) -> 父类(超类)

The relationship between classes and interfaces

1 类与类之间的关系;
	可以是继承关系, extends来描述继承关系;   单继承

2 类与接口之间的关系;
	是一个实现的关系;  implements 某个类实现了多个接口; 多实现 
	语法:   A implements IB1,IB2,IB3...{}

3 接口与接口之间的关系;
	接口继承接口; extends关键字来描述;
	IA extends IB1,IB2,IB3...{}
	接口与接口之间继承的是什么东西 : 会将我们所有的属性,抽象方法全部通通继承过来.
Released two original articles · won praise 0 · Views 14

Guess you like

Origin blog.csdn.net/weixin_43952429/article/details/104525925