public interface Person {
void printStr();
String getStr();
}
public class Persion2 implements Person {
public void printStr(){
System.out.println("hello world");
}
public String getStr(){
return "return hello world";
}
}
public class Main {
public static void main(String[] args) {
Person p = new Persion2();
p.printStr();
String str = p.getStr();
System.out.println(str);
}
}
总结:实现接口的类必须实现接口的所有方法