• 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學習筆記 Class  & Constructor

2022 年 3 月 29 日
Home Reading Programming

 public class Circle     {  

    public double x;

      public double y;

        public double radius;

//用Excel的概念來理解,假設我們要在指定的儲存格裡面輸入值,我們只要知道地址就可以,但是如果沒有儲存格怎麼辦呢?我們要先建立儲存格,我們要建立一種叫Circle的儲存格,這個儲存格裡面有3個欄位,doube形式的x,y,radius。

    public Circle(double x, double y, double radius) {

        this.x = x;

        this.y = y;

        this.radius = radius;

    }

//還要設定怎樣取值,this.x即是這個Circle格的x取值為Circle(double x…….)。

    public Circle(double x, double y) {

        this(x,y,10);

   }

//constructor是為了減少初始取值的錯誤,將參數跟變數放進去Circle裡面,所以如果Circle有三欄,三欄都要有值?這個constructor有賦值x,y,radius預設為10。

    public Circle() {

        this(5, 5, 1);

    }

這個constructor有賦值x,y,radius預設為5,5,1。

     public Circle(double y){

        this(y,99,98) ;

     }

這個constructor有賦值x,y,radius預設為y,99,98。This.x的取值為y,不要搞錯。

    public static void main(String[] args) {

        Circle circle = new Circle();

        System.out.println(circle.x + ” ” + circle.y + ” ” + circle.radius);

// 執行結果: 5.0 5.0 1.0

        Circle anotherCircle = new Circle(10, 5);

        System.out.println(anotherCircle.x + ” ” + anotherCircle.y + ” ” + anotherCircle.radius);

// 執行結果: 10.0 5.0 10.0

      Circle anotherCircle1 = new Circle(10);

        System.out.println(anotherCircle1.x + ” ” + anotherCircle1.y + ” ” + anotherCircle1.radius);

    }

}

// 執行結果: 10.0 99.0 98.0     

Tags: 程式學習JAVA
Share120Tweet75Share30
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