示例:
package com.shun.method; public class Demo02 { public static void main(String[] args) { //方法的定义 int max = max(10, 20); //double max = max(10, 20); System.out.println(max); } //比大小 public static int max(int a , int b){ int result = 0; if (a==b){ System.out.println("a==b"); return 0; } if (a>b){ result = a; }else { result = b; } return result; } //方法重载 public static double max(double a , double b){ double result = 0; if (a==b){ System.out.println("a==b"); return 0; } if (a>b){ result = a; }else { result = b; } return result; } }