定义一个computer类
package com.company;
public interface computer{
/定义公告,静态,常量/
public static final int MAX_NUM=5000;
/接口中只允许定义公共的抽象方法/
public abstract double couunt(double num1,double num2,char tag);
}
定义一个实现computerImp类去实现
package com.company;
public class computerImp implements computer {
/* public double count(double num1,double num2,char tag){
if(tag ==’+’)
return num1+num2;
else
return num1-num2;
}*/
@Override
public double couunt(double num1, double num2, char tag) {if(tag =='+')return num1+num2;elsereturn num1-num2;
}
}
定义一个测试类
package com.company;
public class test {
public static void main(String[] args){
computer com;
com = new computerImp();
double res=com.couunt(10,10,’+’);
System.out.println(res);
}
}