java interface接口的传值方法

A 类

package interface_test;

public class A {
   private IPresenter ip;
   public A(IPresenter ip) {
	   this.ip = ip;
	   set();
   }
   
   public void set() {
	   ip.codeMsg("A class");
   }
   
}

interface 接口

package interface_test;

public interface IPresenter {
	void codeMsg(String str);
}

test 类

package interface_test;

public class test implements IPresenter {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			 new A(new test());
	}

	@Override
	public void codeMsg(String str) {
		// TODO Auto-generated method stub
		System.out.println(str);
	}

}
posted @ 2018-09-27 22:14  zhaocundang  阅读(3399)  评论(0编辑  收藏  举报