zoukankan      html  css  js  c++  java
  • 方法的重载理解

    体会:
      相同:方法名一定要相同,一定要在同一个类中
      不同:参数类型、参数顺序、参数数量(任一一个不同就满足重载条件)
      重载方法与返回类型、形参无关。
    例子:下面与本体重载的除了注释的,都满足
     1 public class Aa{
     2   //本体
     3   public static void f(int a,char b,boolean c){
     4     System.out.println("自己");
     5   }
     6  
     7   //重载方法
     8   public static void f(char b,int a,boolean c){
     9     System.out.println("aa");
    10   }
    11   public static int f(boolean a,char c,int b){
    12     System.out.println("bb");
    13     return 0;
    14   }
    15   public static void f(int a,char b,double c){
    16     System.out.println("cc");
    17   }
    18   // 只改变形参名字,没有意义
    19   // public static void f(int x,char y,boolean z){
    20     // System.out.println("dd");
    21   // }
    22   public static int f(int x,double y){
    23     System.out.println("ee");
    24   return 0;
    25   }
    26   //只改变返回类型,没有意义
    27   // public static int f(int x,char y,boolean z){
    28     // System.out.println("ff");
    29     // return 0;
    30   // }
    31  
    32   public static void main(String[] args) {
    33     f(1,'a',true);
    34     f('a',1,true);
    35     int a = f(true,'a',1);
    36     f(1,'a',1.0);
    37     //f('a',1,true); 错误
    38     int b = f(1,1.0);
    39     //int c = f(1,'a',true); 错误
    40   }
    41 }
  • 相关阅读:
    POWERSHELL脚本执行权限
    tcp连接状态查看
    shutdown vs close
    tcp timestamps
    与TIME_WAIT相关的几个内核参数修改测试讨论结论
    添加 vip
    tcp nonblock connection rst
    tcp keepalive选项
    grep搜索文本
    protobuf 测试使用
  • 原文地址:https://www.cnblogs.com/zou-zou/p/8608438.html
Copyright © 2011-2022 走看看