java interface源码,interfacetest.java 源代码在线查看 - Java程序设计培训教程2 资源下载 虫虫电子下载站...

class InterfaceImp2 implements a2.Action{double num = 50;public void addValue(int n){num += (n+1)*n/2;}public void subtractValue(int n){num -= (n+1)*n/2;}public void factorialValue(int n){num = 1;for(int i =1;i{num *= i;}}public double getValue(){return num;}}public class InterfaceTest{public static void main(String args[]){double i;a2.InterfaceImp1 classObj1 = new a2.InterfaceImp1();i = classObj1.getValue();System.out.println("The original value in InterfaceImp1 is:"+i);if(i{classObj1.addValue(20);i = classObj1.getValue();System.out.println("After call addValue method, value of InterfaceImp1 is:"+i);}else{classObj1.subtractValue(30);i = classObj1.getValue();System.out.println("After call subtractValue method, value of InterfaceImp1 is:"+i);}classObj1.factorialValue(6);i = classObj1.getValue();System.out.println("After call factorialValue method, value of InterfaceImp1 is:"+i);InterfaceImp2 classObj2 = new InterfaceImp2();i = classObj2.getValue();System.out.println("The original value of InterfaceImp2 is:"+i);if(i{classObj2.addValue(40);i = classObj2.getValue();System.out.println("After call addValue method, value of InterfaceImp2 is:"+i);}else{classObj2.subtractValue(40);i = classObj2.getValue();System.out.println("After call subtractValue method, value of InterfaceImp2 is:"+i);}classObj2.factorialValue(8);i = classObj2.getValue();System.out.println("After call factorialValue method, value of InterfaceImp2 is:"+i);}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值