jash.liao的JAVA整理教學:JAVA件導向-方法過載(overlaod)

jash.liao的JAVA整理教學:JAVA件導向-方法過載(overlaod)

jash.liao的JAVA整理教學:JAVA件導向方法過載(overlaod

 

線上執行:http://www.tutorialspoint.com/compile_java_online.php / http://www.compilejava.net/

code2htmlhttp://tohtml.com/ 

 

publicclass HelloWorld{
    publicint add(int a,int b){
        return a + b;
    }
     
    publicdouble add(double a,int b){
        return a + b;
    }
     
    publicdouble add(int a,double b){
        return a + b;
    }
     
    publicdouble add(double a,double b){
        return a + b;
    }
     publicstaticvoid main(String[]args){
        System.out.println("Hello World");
        HelloWorld demo =new HelloWorld();
        int n1 =2;
        int n2 =4;
        double n3 =2.5;
        double n4 =3.8;
         
        System.out.println(n1 +"+"+ n2 +"="+ demo.add(n1, n2));
        System.out.println(n1 +"+"+ n3 +"="+ demo.add(n1, n3));
        System.out.println(n4 +"+"+ n2 +"="+ demo.add(n4, n2));
        System.out.println(n3 +"+"+ n4 +"="+ demo.add(n3, n4));        
     }
}

 

 

 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *