interface Runable {
public void run() ;
}
class Cat implements Runable {
@Override
public void run() {
System.out.println("猫急上树..") ;
}
}
class Dog implements Runable {
@Override
public void run() {
System.out.println("狗急跳墙..") ;
}
}
public class RunTest {
public static void main(String args[]) {
Runable r = new Cat() ;
r.run() ;
System.out.println("------------") ;
r = new Dog() ; //会产生垃圾
r.run() ;
}
}
Cat.run()->r.run()
Dog.run()->r.run()