A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 高双武 黑马帝   /  2011-11-14 09:37  /  1311 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 wudiisss 于 2011-11-14 09:38 编辑

请问下面这个程序算是面向接口编程吗?突然想起来的一个设计模式,然后就写了一段代码,自己也不太确定算不算,

package students;
import java.math.*;
public class Test {
        public static void main(String [] args){
                Thing a=new Stone();               
                a.throwThing(20,12);               
        }
}
class Stone implements Thing{       
        public void throwThing(double vv,double hh){
                double dis=Math.sqrt(vv*2*hh/10);
                System.out.println("石头"+dis);
        }
}
class Paper implements Thing{
        public void throwThing(double vv,double hh){
                double dis=Math.sqrt(vv*2*hh/10);
                System.out.println("纸团"+dis);
        }
}

//接口是
public interface Thing{
        public void throwThing(double a,double b);
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马