Home > Java > javaTutorial > body text

Java Example - Overloaded Method Exception Handling

黄舟
Release: 2017-02-04 10:09:42
Original
912 people have browsed it

The following example demonstrates the exception handling of overloaded methods:

/*
 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);
      }
   }
   }
Copy after login

The output result of running the above code is:

30.0
27.0
27.0
exception occoure: java.lang.ArithmeticException: / by zero
Copy after login

The above is the Java example - the content of overloaded method exception handling , for more related content, please pay attention to the PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!