• 方法重载


     1 package day05;
     2 
     3 public class OverloadDemo {
     4     /*  使用方法重载思想设计比较两个数是否相同的方法,
     5        兼容全整数类型(byte、short、int、long)*/
     6     public static void main(String[] args) {
     7         short a = 10;
     8         short b = 20;
     9         System.out.println(compare(a, b));
    10     }
    11 
    12     public static boolean compare(int a, int b) {
    13         return a == b;
    14     }
    15 
    16     public static boolean compare(byte a, byte b) {
    17         return a == b;
    18     }
    19 
    20     public static boolean compare(short a, short b) {
    21         return a == b;
    22     }
    23 
    24     public static boolean compare(long a, long b) {
    25         return a == b;
    26     }
    27 }

    执行结果:

    欢迎批评指正,提出问题,谢谢!
  • 相关阅读:
    CISCO一些基本配置
    每日学习
    每日学习(个人作业2)
    每日学习
    团队冲刺第十四天
    每日学习
    团队冲刺第十三天
    每日学习
    团队冲刺第十二天
    2021.5.26
  • 原文地址:https://www.cnblogs.com/xxeleanor/p/14218850.html
Copyright © 2020-2023  润新知