public class Rec implements Shape {private double len,wid;public Rec(double len, double wid){this.len = len;this.wid = wid;}@Overridepublic double getArea() {if(len < 0 || wid < 0) {throw new RuntimeException("参数不能为负数!!!");}return len * wid;}public static void main(String[] args) {Rec r = new Rec(5.00,3.00);System.out.println(r.getArea());}}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |