静态方法中,只能访问静态。非静态方法可以访问所有。静态方法中没有this关键字。
package myStatic.a04staticdemo04;
public class Student {
String name;
int age;
static String teacherName;
//this:表示当前方法调用者的地址值
//这个this:由虚拟机赋值的。
public void show1(Student this){
System.out.println("this:"+this);
System.out.println(name+","+age+","+teacherName);
//调用其他方法
this.show2();
}
public void show2(){
System.out.println("show2");
}
public static void method(){
System.out.println("静态方法");
}
}
package myStatic.a04staticdemo04;
public class StudentTest {
public static void main(String[] args) {
Student.teacherName="karry老师";
Student s1=new Student();
System.out.println("s1:"+s1);
s1.name="张三";
s1.age=23;
s1.show1();
System.out.println("******");
Student s2=new Student();
System.out.println("s2:"+s2);
s2.name="lisi";
s2.age=24;
s2.show1();
}
}