interface Act{
void act();
}
class Actor1 implements Act{
public void act(){
System.out.println("To be,or not to be");
}
}
class Actor2 implements Act{
public void act(){
System.out.println("Wherefore art thou Romeo?");
}
}
public class TryOut{
public static void main(String []args){
Actor1 hamlet=new Actor1();
Actor2 juliet=new Actor2();
tryout(hamlet);
tryout(juliet);
}
private static void tryout(Act actor){
actor.act();
}
}
Actor1,Actor2不是实现接口的方法了吗?语句
tryout(hamlet);
tryout(juliet);
private static void tryout(Act actor)
actor.act();不要了不行吗?
void act();
}
class Actor1 implements Act{
public void act(){
System.out.println("To be,or not to be");
}
}
class Actor2 implements Act{
public void act(){
System.out.println("Wherefore art thou Romeo?");
}
}
public class TryOut{
public static void main(String []args){
Actor1 hamlet=new Actor1();
Actor2 juliet=new Actor2();
tryout(hamlet);
tryout(juliet);
}
private static void tryout(Act actor){
actor.act();
}
}
Actor1,Actor2不是实现接口的方法了吗?语句
tryout(hamlet);
tryout(juliet);
private static void tryout(Act actor)
actor.act();不要了不行吗?
Actor1 hamlet=new Actor1(); hamlet.act();
Actor2 juliet=new Actor2(); juliet.act();
这样当然可以。但是我觉得这个例子是为了说明hamlet和juliet都是Act类型。
public class TryOut{
public static void main(String []args){
Actor1 hamlet=new Actor1();
Actor2 juliet=new Actor2();
hamlet.act();
juliet.act();
}
}
#1才是正解yuzl32(Hello!有酒醉)这样做有什么意义。根本体现不了接口的特点。