class Info:
def __init__(self, name):
self.name = name # 例項變數
@classmethod
def fetch(cls):
print(cls)
Info.fetch() # 呼叫靜態方法,不需要建立物件,也不需傳self引數
16 ##### 適合類方法的場景:方法內部如果需要使用當前類的話
相關文章
- 16 ##### 適合靜態方法的場景:方法中不使用物件的值,則直接使用靜態方法物件
- 14 #### 方法分類與使用場景(繫結、靜態、類方法)
- java內部類,為什麼需要內部類?Java
- Java在方法作用域內建立的內部類Java
- 獲取當前會話資訊的方法會話
- Java內部類和匿名內部類的用法Java
- Java中的巢狀類、內部類、靜態內部類Java巢狀
- java內部類,區域性內部類,靜態內部類,匿名內部類Java
- 獲取當前會話資訊的方法(二)會話
- 通過反射獲取類的類名,方法和內部成員變數反射變數
- java之內部類(InnerClass)----非靜態內部類、靜態內部類、區域性內部類、匿名內部類Java
- 10-Java內部類——成員內部類、區域性內部類、匿名內部類Java
- Java中的匿名內部類及內部類的二三事Java
- java內部類之成員內部類之匿名內部類Java
- java的內部類Java
- 注意!非靜態內部類和非靜態方法的匿名類的this$0屬性
- 萬能PHP Curl封裝類,適合多個場景,呼叫方便!PHP封裝
- java內部類之成員內部類之區域性內部類Java
- Java內部類詳解--匿名內部類Java
- java內部類之成員內部類Java
- Java 的抽象類, 介面以及內部類Java抽象
- Socket類的getInputStream方法與getOutputStream方法的使用
- 內部類
- 15 ##### 適合繫結方法的場景:在物件中封裝值,在方法中讀取物件的值物件封裝
- java內部類的理解Java
- java中的內部類Java
- 檢視當前會話session id方法:會話Session
- Java的特殊類用法:檔案類、內部類、本地類、匿名類Java
- javaSE-day04--ArrayList基本用方法、類內定義方法和方法過載、靜態方法static(類的方法)、工具方法(static)的定義和使用Java
- Java內部類詳解-- 成員內部類Java
- 排名前16的Java工具類Java
- String的intern方法使用場景
- 【JAVA】筆記(6)--- toString方法;equals方法;finalize方法;package與import;內部類;Java筆記PackageImport
- 淺談日本伺服器適合的使用場景伺服器
- 最適合使用RxJava處理的四種場景RxJava
- 什麼業務場景適合使用Redis?Redis
- Java 內部類使用詳解Java
- 抽象類和匿名方法的使用抽象