java方法使用
1 在方法中可以調用同一個類中的方法和屬性,但是不能定義方法。system.out語句只能在方法中
2 方法重載:(1)同一個類中 (2)方法名相同 (3)參數列表的類型不同或者個數不同?
代碼:
public class Method1 {
//方法重載求2個數的最大值
??? public static void main(String[] args) {
??????? Method1 m = new Method1();
??????? System.out.println(m.max(34, 89));
??????? System.out.println(m.max(32.4, 32.1));
??????? System.out.println(m.max(546, 345, 554));
???????
??? }
??? public int max(int a,int b){
??????? return (a>b)? a : b;
??? }
??? public double max(double a,double b){
??????? return (a>b)? a : b;
??? }
??? public double max(double a,double b,double c){
??????? return (max(a,b)>c)? max(a,b) : c;
??? }
}
轉載于:https://www.cnblogs.com/yjtm53/p/4125362.html
總結
- 上一篇: 构建五种机器学习模型作比较(某金融数据集
- 下一篇: 有趣的Web版Ubuntu Linux