我想做这个练习,但我有点挣扎。 它说:
"Write a static method print which takes an array of objects whose class implements Printable, and prints each element in the array, one element per line. Check it by placing it in an otherwise empty class and compiling it. "
如何编写一个以实现接口(interface)的参数对象为参数的方法,我假设我需要使用“implements Printable”,但是在哪里?无法弄清楚..我知道如何在类里面做到这一点,但是...方法?
最佳答案
您的静态方法需要接受 Printable 数组作为其参数,例如
public static void print(Printable[] printables)
关于java - 具有实现接口(interface)的对象的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20621717/