更新时间:2022-01-18 04:24:12
您必须在接口中声明要在这种情况下使用的所有方法.该界面对printSomethingElse一无所知,这就是为什么您遇到上述错误的原因.
You have to declare all methods that you want to use in that case in the interface. The interface knows nothing of printSomethingElse and that is why you're getting the above error.
接口的目的是使您可以在多个相似的已实现类之间拥有通用的功能列表.例如,List
是一个接口,其中包含由不同类以各种方式实现的功能的列表",例如,LinkedList
使用双向链接列表来提供List
和ArrayList
的功能,动态扩展数组可以做到这一点.
The purpose of an Interface is so that you can have a common list of functions across multiple similar implemented classes. For example, List
is an interface which contains a 'list' of functions implemented in various ways by different classes such as LinkedList
which uses a Doubly Linked list to provide the functionality of List
and ArrayList
which uses an Dynamically expanding array to do so.