ไม่ "นี่ " ไม่สามารถใช้คีย์เวิร์ดเพื่ออ้างถึงสมาชิกสแตติกของคลาสได้ เนื่องจาก "นี่ ” คำสำคัญ ชี้ไปที่วัตถุปัจจุบัน ของคลาสและสมาชิกสแตติกไม่ต้องการวัตถุใด ๆ ที่จะเรียก สมาชิกแบบคงที่ของคลาสสามารถเข้าถึงได้โดยตรง โดยไม่ต้องสร้างวัตถุ t ใน Java
ตัวอย่าง
public class StaticTest {
static int a = 50;
static int b;
static void show() {
System.out.println("Inside the show() method");
b = a + 5;
}
public static void main(String[] args) {
show();
System.out.println("The value of a is: " + a);
System.out.println("The value of b is: " + b);
}
} ผลลัพธ์
Inise the show() method The value of a is: 50 The value of b is: 55