官术网_书友最值得收藏!

Interfaces

Interfaces are the reference types in Java. They are used in Java to define contracts among classes. Any class that implements that interface has to adhere to the contract that the interface defines.

For example, we have an interface car as follows that consists of three abstract methods:

public interface Car { 
   void shape(); 
   void price(); 
   void color(); 
} 

Any class that implements this interface has to implement all the abstract methods of this interface unless it is an abstract class. Interfaces can only be implemented or extended by other interfaces, they cannot be instantiated.

Prior to Java 8, interfaces consisted only of abstract methods and final variables. In Java 8, interfaces may contain default and static methods as well.

主站蜘蛛池模板: 东兴市| 金堂县| 五常市| 曲水县| 龙海市| 海南省| 错那县| 贡觉县| 阜平县| 开封县| 广水市| 团风县| 綦江县| 隆林| 集安市| 长泰县| 南澳县| 察雅县| 高陵县| 玉门市| 米林县| 察雅县| 广东省| 绵阳市| 安徽省| 商都县| 嘉义市| 凤翔县| 虞城县| 长沙县| 平陆县| 边坝县| 岳池县| 海安县| 皮山县| 兴国县| 浑源县| 北票市| 四会市| 奉化市| 仁化县|