• Home
  • Market
  • Finance
  • Running
  • Reading
  • Research
  • Travel
  • Lifestyle
  • About Me
No Result
View All Result
  • Home
  • Market
  • Finance
  • Running
  • Reading
  • Research
  • Travel
  • Lifestyle
  • About Me
No Result
View All Result
閱讀、跑步與書寫 ~~只要努力學習,知識一定能夠成為力量

JAVA學習筆記 Static

2022 年 3 月 29 日
Home Reading Programming

 關於這部份我參考了「Ken Yang筆記」,寫得很清楚,例子也很好懂。

class test{
static int iValue = 0;
public test() {
}
}
public class main {
public static void main(String[] argv)  {
test test1 = new test();
test test2 = new test();
System.out.println(test1.iValue);
test2.iValue  = 10;
System.out.println(test2.iValue);
System.out.println(test1.iValue);
}
}

特性1:只有一個值

class 的test裡面宣告一個ivalue的static = 0,

所以test1.ivalue印出來是多少呢?當然是1嘛。

接下來,test2.ivalue賦值為10,

所以,test2.ivalue印出來會是多少呢?答案是10,沒有問題。

再來,回頭把test1.ivalue印出來又會是多少呢?很簡單嘛,是0,

真的嗎?實際結果是10啊,為什麼呢?這就是static的持性,

Ivalue只佔一組記憶體,不管你是test1到test10,itest的值卻只有一個。

特性2:可直接取用

class test{
static int iValue = 0;
public test() {
}
}
public class main {
public static void main(String[] argv)  {
System.out.println(test.iValue);
}
}

即使不new object出來,可直接取用test.ivalue。

換言之,如果class test裡面的static刪掉,則不能直接取用。

Tags: 程式學習JAVA
Share122Tweet76Share31
Charlie chacha

Charlie chacha

Related Posts

持續買進
Finance

關於投資,讀《持續買進》的心得

2024 年 4 月 24 日

今天我們來分享一下最近非常熱門的財經書籍《持續買進》,怎麼說呢?整本書讀下來,也是有所收獲,可是,我個人覺得沒有外界所說那麼高度評價。 其實這本書所說的策略或建議也不是什麼新鮮的東西,只是作者用了一個...

EXCEL VLOOKUP 文字轉數字 數字轉文字
Programming

自學Excel系列 – 使用Vlookup函數的1個小技巧, 文字與數字之間的轉換問題(文字轉數字 數字轉文字)

2023 年 7 月 6 日

Vlookup函數 Vlookup的泛用性相信學過Excel的人都應該知道,有時候因為資料的性質,我們無法(最主要是沒有時間)一格一格去改變資料的屬性,導致我們使用Vlookup時無法找到目標的值,所...

自學Excel VBA系列-如何用VBA控制OutLook?
Lifestyle

Excel強大的組合函數練習,資料庫關鍵字搜索,Address + Match + Index + Find 組合拳

2023 年 3 月 18 日

想要把Excel的功能變得強大,函數組合使用必不可少,例如之前介紹的Offset函數,《一個強大的Excel函數OFFSET,動態選取資料範圍》,非常好用。本文介紹另外一個經常會使用到的組合拳:Add...

AI人工智能
Market

探索人工智能,了解OpenAI的未來與潛力–ChatGPT使用心得 ChatGPT可以幫到你做什麼?人工智能 語言生成 數據分析

2023 年 7 月 6 日

OpenAI ChatGPT ChatGPT的名號,大家都應該非常熟悉。地區破解什麼就不討論,兩個條件,地區VPN,以及SMS認證服務,還不能是虛擬號碼,我花了幾天時間也找不到方便安全的省錢方法,建議...

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

About Me

閱讀、跑步與書寫 ~~只要努力學習,知識一定能夠成為力量

Charlie Chacha

Blogger and Runner

Welcome to my blog! I'm Charlie Chacha, and here I'll be sharing valuable insights on living a fulfilling life and achieving financial success. Join me as we delve into topics such as effective time management, personal growth, and the art of learning. I firmly believe that putting in the effort and embracing continuous learning is the key to unlocking a prosperous future. So, let's embark on this journey together and discover how to thrive in both life and finances!

Categories

  • Finance (37)
  • Lifestyle (7)
  • Market (22)
  • Programming (13)
  • Reading (41)
  • Research (21)
  • Running (41)
  • Sports (2)
  • Travel (3)
  • Uncategorized (1)

Popular

  • JAVA學習筆記 ArrayList

    一個強大的Excel函數OFFSET,動態選取資料範圍

    2401 shares
    Share 960 Tweet 600
  • Excel VBA的自學心得分享

    1915 shares
    Share 766 Tweet 479
  • 自學Excel VBA系列-如何用VBA控制WORD?

    1430 shares
    Share 572 Tweet 358
  • 自學Excel VBA系列-如何用VBA控制OutLook?

    1189 shares
    Share 476 Tweet 297
  • 自學Excel系列 – 使用Vlookup函數的1個小技巧, 文字與數字之間的轉換問題(文字轉數字 數字轉文字)

    621 shares
    Share 248 Tweet 155

Instagram

    Go to the Customizer > JNews : Social, Like & View > Instagram Feed Setting, to connect your Instagram account.
No Result
View All Result
  • Home
  • Market
  • Finance
  • Running
  • Reading
  • Research
  • Travel
  • Lifestyle
  • About Me