方法回顾
public class Demo01 {
public static void main(String[] args) {
}
public String sayHello(){
return "hello,world";
}
public int max(int a , int b){
return a>b? a: b;
}
public void readFile(String file) throws IOException {
}
}
静态方法与非静态方法
public class Student {
public static void say1(){
System.out.println("学生说话了");
}
public void say2(){
System.out.println("学生说话了");
}
}
Student.say1();
Student student = new Student();
student.say2();
值传递与引用传递
public static void main(String[] args) {
int a = 1;
Demo04.change(a);
System.out.println(a);
}
public static void change(int a){
a = 10;
}
public class Demo05 {
public static void main(String[] args) {
Person person = new Person();
System.out.println(person.name);
Demo05.change(person);
System.out.println(person.name);
}
public static void change(Person person){
person.name = "秦江";
}
}
class Person{
String name;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步