java中的域是什嗎?__java編程思想

來源:互聯網
上載者:User

多態在域的問題上是特殊的。我理解不了中文版的書直接叫域,看了英文原版,原版寫的是fields,直接翻譯雖然沒錯,但是出問題的變數不是域。特地查了what is the meaning of field in java。很多人把它看成是由花括弧括起來的一個範圍。其實架構裡面也有一種東西——domain model,這個也叫域,領域模型。


然後找到這篇文章

What is a field in java?


A field is an attribute. A field may be a class's variable, an object's variable, an object's method's variable, or a parameter of a function.

class bike{   static int bikes;  int gear;  int cadence;  void create( int newGear, int newCadence ){    bikes = bikes + 1;    gear = newGear;    cadence = newCadence;}  int getSpeed(){    int speed = gear*cadence*5*3.141;    return speed;  }}

'bikes' is a class's variable (class variable) (static field).
'gear' and 'cadence' could be an object's variables (instance variables) (non-static fields).
'speed' is an object's method's variable (local variable).
'newGear' and 'newCadence' are parameters of a function (parameters).


field,域是一種屬性,可以是一個類變數,一個物件變數,一個對象方法變數或者是一個函數的參數。(補充,class‘s variables,類的執行個體變數和靜態變數稱為class's variables,類屬變數,也稱類變數或資料域,其實翻譯成屬性也可以,類屬性,聽起來不會怪怪的,來自百度百科)。


class bike{   static int bikes;  int gear;  int cadence;  void create( int newGear, int newCadence ){    bikes = bikes + 1;    gear = newGear;    cadence = newCadence;}  int getSpeed(){    int speed = gear*cadence*5*3.141;    return speed;  }}


bikes是一個類變數(靜態域)。

gear 和 cadence 是物件變數(執行個體變數)(非靜態域)。

(這裡有一點點小矛盾,其實這樣照百科這樣說,那麼bikes、gear和cadence都是類變數,bikes是類變數中的靜態變數,而gear和cadence是類變數中的執行個體變數。)


speed是對象方法的變數(局部變數)。

(看到沒有,local variable,java沒有出現gobal variable,全域變數,要說的話類變數的作用範圍和全域變數一樣,只不過不那樣叫)。


newGear和newCadence是函數(方法)的參數(參數)。




原文地址:http://www.answers.com/Q/What_is_a_field_in_java

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.