zoukankan      html  css  js  c++  java
  • day4 函数重载

    函数的重载  

    1、函数重载的定义:在同一个类中,有一个以上的同名函数,只要函数的参数列表或参数类型不一样即可,与返回值无关, 这些统称为方法的重载。

    2、函数的重载存在的原因:为了增强方法的阅读性,优化了程序设计。

    案例1:九九乘法表

     1 private static void print99() {
     2         for(int i = 1 ; i<= 9 ; i ++){
     3             for(int j = 1 ; j<=i ; j++){
     4                 System.out.print(i+"*"+j+"="+(i*j)+" ");
     5             }
     6             System.out.println();
     7         }
     8     }
     9 
    10 
    11     private static void print99(int num) {
    12         for(int i = 1 ; i<= num ; i ++){
    13             for(int j = 1 ; j<=i ; j++){
    14                 System.out.print(i+"*"+j+"="+(i*j)+" ");
    15             }
    16             System.out.println();
    17         }
    18 }

    练习:判断那个方法是重载

    1 void  show(int  w, double c, char b){}     
    2 
    3 
    4 void show(int x, char y, double z){}   true       
    5  void show(int a, double c, char b){}     false  
    6 
    7 void show(int a, char b){}   true
    8 void show(double c){}   true
    9 double show(int x, char y, double z){}   true
  • 相关阅读:
    maven常用命令介绍(持续更新)
    JQ笔记
    AspNetPager学习使用2
    AspNetPager学习使用1
    VS2012添加ADO实体数据模型
    手动拍摄0008
    程序自动拍摄0007
    曝光补偿0006
    白平衡0005
    感光度0004
  • 原文地址:https://www.cnblogs.com/Michael2397/p/5944083.html
Copyright © 2011-2022 走看看