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

How to create java interface implementation class

WBOY
Release: 2023-04-30 23:37:06
forward
1549 people have browsed it

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修饰符
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template