From 1e38561dc79da07bb3c91a2fce23e48a2565df4d Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Thu, 25 Dec 2025 14:04:42 +0800 Subject: [PATCH] =?UTF-8?q?day04-=E6=96=B9=E6=B3=95=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E6=A6=82=E5=BF=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day04/src/com/inmind/Demo04_overload.java | 81 +++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 day04/src/com/inmind/Demo04_overload.java diff --git a/day04/src/com/inmind/Demo04_overload.java b/day04/src/com/inmind/Demo04_overload.java new file mode 100644 index 0000000..98c3f99 --- /dev/null +++ b/day04/src/com/inmind/Demo04_overload.java @@ -0,0 +1,81 @@ +package com.inmind; +/* +方法重载:指在同一个类中,允许存在一个以上的同名方法,只要它们的参数列表不同即可,与修饰符和返 + 回值类型无关。 + + 方法重载:2同一不同 + 1.在同一个类中 + 2.方法名相同 + 3.参数列表不同,(与修饰符和返回值类型无关)(参数列表不同:参数列表中的个数,数据类型,参数的顺序) + + 重载的作用:只要记忆同一个方法名,就可以实现对应多种的功能 + --------------------------------------------------------------- + + class Demo +{ + void show(int a,float b,char c) + { + + } +} +下列哪些函数和给定函数重载了。 +a.int show(int x,float y,char z) + +b.void show(float b,int a,char c) + +c.void show(int c,float a,char b) + +d.void show(int a,int b,int c) + +e.double show() + + */ +public class Demo04_overload { + void show(int a,float b,char c) + { + + } + + void show(int a,int b,int c){ + + } + + double show(){ + return 1.1; + } + + void show(float b,int a,char c){ + + } + + + + public static void main(String[] args) { + //定义2个整数相加之和的方法,并返回和值 + //定义3个整数相加之和的方法,并返回和值 + //定义4个整数相加之和的方法,并返回和值 + int sum = getSum(1, 2, 3); + System.out.println(sum); + System.out.println(1); + System.out.println(1.1); + System.out.println(true); + System.out.println("edd"); + System.out.println('d'); + } + + //定义2个整数相加之和的方法,并返回和值 + public static int getSum(int a, int b) { + int sum = a+b; + return sum; + } + //定义3个整数相加之和的方法,并返回和值 + public static int getSum(int a, int b,int c) { + int sum = a+b+c; + return sum; + } + //定义4个整数相加之和的方法,并返回和值 + public static int getSum(int a, int b,int c,int d) { + int sum = a+b+c+d; + return sum; + } +}