您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java 实例 - 重载方法异常处理

2024/3/14 3:29:27发布24次查看
以下实例演示了重载方法的异常处理:
/* author by w3cschool.cc main.java */public class main { double method(int i) throws exception{ return i/0; } boolean method(boolean b) { return !b; } static double method(int x, double y) throws exception { return x + y ; } static double method(double x, double y) { return x + y - 3; } public static void main(string[] args) { main mn = new main(); try{ system.out.println(method(10, 20.0)); system.out.println(method(10.0, 20)); system.out.println(method(10.0, 20.0)); system.out.println(mn.method(10)); } catch (exception ex){ system.out.println("exception occoure: "+ ex); } } }
以上代码运行输出结果为:
30.0 27.0 27.0 exception occoure: java.lang.arithmeticexception: / by zero
以上就是java 实例 - 重载方法异常处理的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product