静态方法
public class Student {
public static void say(){
System.out.println("学生说话了");
}
}
public class Demo1{
public static void main(String[] args){
Student.say(); //可直接调用
}
}
非静态方法
public class Student {
public void say(){
System.out.println("学生说话了");
}
}
public class Demo2{
public static void main(String[] args){
//实例化这个类 new
//对象类型 对象名 = 对象值
Student student = new Student();
student.say();
}
}
值传递与引用传递
值传递
package com.oop.demo01;
public class PassByValue {
public static void main(String[] args) {
int a = 1;
System.out.println(a);
PassByValue.change(a);
System.out.println(a); //1
}
//值传递
public static void change(int a){
a = 10;
}
}
引用传递
package com.oop.demo01;
public class PassByReference {
public static void main(String[] args) {
Person person1 = new Person();
System.out.println(person1.name); //null
PassByReference.change(person1);
System.out.println(person1.name); //BIT0
}
//引用传递 传入参数是Person类中的person1对象,可以改变他的属性!
public static void change(Person person){
person.name = "BIT0";
}
}
class Person{
String name; //null
}



