Home  >  Article  >  Java  >  How to create java interface implementation class

How to create java interface implementation class

WBOY
WBOYforward
2023-04-30 23:37:061517browse

1. Creation instructions

(1) When Java uses interface variables to call a method that implements a class object, the method must be declared in the interface. In the interface implementation class, The method's type and parameters must correctly match those defined in the interface.

(2) The variables declared by the interface are assigned a reference to the object of the interface implementation class, such as List list = new ArrayList();

Here List is the interface, and ArrayList is List. Implementation class.

2. Example

public interface animals {                                          //创建animals接口
    void cry();                                                     //本来是public abstract抽象类但是可以省略
    String getAnimalName();                                         //同上,                       
}                                       
//接口体中包含常量的声明和抽象方法两部分,接口体只有抽象方法,没有普通的方法
//而且接口体中的所有常量 的访问权限一定是public,而且是static常量 ,可以省略public、final、static修饰符
//所有的抽象方法的访问权限都是public,
//!!!!!!!!!!!!!!!!
//所有的抽象方法的访问权限都一定是public,而且允许省略public static修饰符

The above is the detailed content of How to create java interface implementation class. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete