【java】【w3schools】Variables

因爲之前學過C++,在變量類型方面java和C++十分相似,所以只在這裏記錄下與C++不同的地方。

final 關鍵字

you can add the final keyword if you don’t want others (or yourself) to overwrite existing values (this will declare the variable as “final” or “constant”, which means unchangeable and read-only):

final int a = 59;
a = 23;//will generate an error

some regulations for Java Variables

The general rules for constructing names for variables (unique identifiers) are:

Names can contain letters, digits, underscores, and dollar signs
Names must begin with a letter
Names should start with a lowercase letter and it cannot contain whitespace
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (“myVar” and “myvar” are different variables)
Reserved words (like Java keywords, such as int or boolean) cannot be used as names

2020年3月10日16:20:45學到這兒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章