java --接口的回调
public class Sort1 {
public static void main(String[] args) {
AdvertisementBoard ad = new AdvertisementBoard();
ad.show(new white());
}}
interface Advertisement
{
public void showAdvertisement();
public String getCorpName();
}
class white implements Advertisement
{
public void showAdvertisement()
{
System.out.println("i am the white corp ");
}
public String getCorpName()
{
return "white";
}
}
class AdvertisementBoard //这一个类用来使用接口
{
public void show(Advertisement ver) //此行的向上转型为关键步骤,因为最后使用的是实现接口的类,所以用接口声明
{
System.out.println(ver.getCorpName());
ver.showAdvertisement();
}
}