注释 - 静态关键字
最编程
2024-10-18 07:55:51
...
package com.test.Statics2;
import com.test.statics.Student;
public class Test {
public static void main(String[] args) {
// 静态成员中访问非静态成员
// method3() // 错误-不能直接调用,需要new对象调用
Test test01 = new Test();
test01.method3();
}
public static void method1() {
// 静态成员 访问 静态成员
// 同类,直接调用、不同类,类名调用
method2();
Student.drink();
}
public static void method2() {
}
public void method3() {
// 非静态成员 访问 静态成员
// 同类 - 直接调用,new对象调用都可
method1();
Test test02 = new Test();
test02.method3();
// 不同类 - 类名调用
Student.drink();
}
public void method04(){
// 非静态成员 访问 非静态成员
// 同类直接调用
method3();
// 不同类new对象调用
new Person().eat();
}
}