一、方法重载
方法重载:指在同一个类中,存在一个以上的同名方法,它们的参数列表不同即可,与修饰符和返回值类型无关。
参数列表:个数不同,数据类型不同,顺序不同。
重载方法调用:JVM通过方法的参数列表,调用不同的方法。
重载反映的是"随机应变". 同样一项功能, 根据数据类型的不同, 采用不同的处理方式。
二、数组
数组就是存储数据长度固定的容器,保证多个数据的数据类型要一致。
格式:
1.数组存储的数据类型[] 数组名字 = new 数组存储的数据类型[长度];
2.数据类型[] 数组名 = new 数据类型[]{元素1,元素2,元素3...};
3.数据类型[] 数组名 = {元素1,元素2,元素3...};
int[] arr = new int[3];或者
int[] arr = new int[]{1,2,3,4,5};或者
int[] arr = {1,2,3,4,5};
数组访问:数组名[索引] arr[0] = 1;
数组的长度:数组名.length arr.length
数组的存储
数组的存储过程
public static void main(String[] args) {
int[] arr = new int[3];
System.out.println(arr);//[I@5f150435
注意:方法的参数为基本类型时,传递的是数据值. 方法的参数为引用类型时,传递的是地址值.
public static void main(String[] args) {
int a = 1;
int b = 2;
System.out.println(a);//1
System.out.println(b);//2
change(a, b);
System.out.println(a);//1
System.out.println(b);//2
public static void change(int a, int b) {
a = a + b;
b = b + a;
public static void main(String[] args) {
int[] arr = {1,3,5};
System.out.println(arr[0]); //1
change(arr);
System.out.println(arr[0]);//200
public static void change(int[] arr) {
arr[0] = 200;
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.