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

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.

主站蜘蛛池模板: 寿宁县| 刚察县| 武鸣县| 双峰县| 互助| 彭水| 克什克腾旗| 湛江市| 响水县| 什邡市| 河间市| 枣庄市| 健康| 绥化市| 正阳县| 仲巴县| 阿瓦提县| 莆田市| 察雅县| 江北区| 古交市| 彰化市| 大渡口区| 普定县| 鲁甸县| 麻栗坡县| 八宿县| 龙州县| 板桥市| 宜宾县| 荣昌县| 怀远县| 新晃| 沙洋县| 崇仁县| 来凤县| 盐边县| 梅州市| 荣成市| 湘乡市| 静乐县|