Spring入门篇之面向接口编程

Spring入门篇之面向接口编程_第1张图片

例子如下:

1.写一个接口和方法:

package com.wuyonghu.faceinterface;

public interface OneInterface {

        String hello(String word);
}

2.写出实现类:

package com.wuyonghu.faceinterface;

public class OneInterfaceImple implements OneInterface {

    public String hello(String word) {
        return "输入的word是:"+word;
    }

}

3.调用:

package com.wuyonghu.faceinterface;

public class OneInterfaceImplTest {
    public static void main(String[] args) {
            OneInterface interface1=new OneInterfaceImple();
            System.out.println(interface1.hello("Spring"));
    }
}

你可能感兴趣的:(javaWeb框架)