数组使用
1.for-each循环
2.作为方法参数,例:public static int function(int[] array){...};
3.作为方法返回值,例:public static int[] function(...){...};
多维数组
int[][] array = new int[2][3];
Arrays类
面向对象
package com.shifan.oop.demo01;
public class Demo01 {
public static void main(String[] args) {
//修饰符static表示该方法为静态方法,可以直接使用类名调用
System.out.println(Demo01.add(1,4));
//同一类中的静态方法中可直接调用其他静态方法
int sum = add(1,2);
sum = Demo01.add(2,4);
System.out.println(sum);
/*同一个类中静态方法不能直接调用非静态方法
静态方法与类同时加载,非静态方法在类实例化后才加载
例如:int a = fun(2,1);错误*/
/*静态方法中不能直接调用非静态方法,需要先实例化这个类
例如:Student.print();错误*/
//实例化Student类
Student student = new Student();
student.print();
}
public static int add(int a ,int b){
return a+b;
}
public int fun(int a,int b){
return a-b;
}
}
package com.shifan.oop.demo01;
public class Demo02 {
public static void main(String[] args) {
Person person = new Person();
System.out.println(person.name);
change(person);
System.out.println(person.name);
}
public static void change(Person person){
person.name = "时帆";
}
}
/**定义了一个Person类,有一个属性name
* 一个类里面只能有一个public,但可以有多个class
*/
class Person{
String name;
}