一般class內的method就和class內的變數一樣

必須先實體化class後才能夠使用

而static的method的變數和method則是在一開始就給予記憶體空間

配置好該變數與方法,不須宣告就能使用,優點是速度快,缺點是會占用記憶體空間

class名稱對於static像是一個門牌的概念,用來找到static變數和method

class method可以直接使用class與static method與變數
static method能直接使用static method與變數,在使用class method必須先實體化

 

1. 官網https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

01.png

 

2. 範例如下

class method內可以直接使用class和static的變數和方法

static method要使用class內的成員時則要先實體化

02.png  

arrow
arrow

    RX1226 發表在 痞客邦 留言(0) 人氣()