Java關鍵字
Java關鍵字是保留字,表示預定義的動作、內部程序等。因此,關鍵字不能用作變數、函式、物件等的名稱。
關鍵字和識別符號的主要區別在於,關鍵字是表示預定義動作的保留字,而識別符號是變數、函式、物件等的名稱。
一些Java關鍵字如下:
| abstract | assert | boolean | break |
| byte | case | catch | char |
| class | const | continue | default |
| do | double | else | enum |
| extends | final | finally | float |
| for | goto | if | implements |
| import | instanceof | int | interface |
| long | native | new | package |
| private | protected | public | return |
| short | static | strictfp | super |
| switch | synchronized | this | throw |
| throws | transient | try | void |
| volatile | while |
一個演示關鍵字的程式如下:
示例
public class Example {
public static void main(String[] args) {
int i = 5;
char c = 'A';
System.out.println("i = " + i);
System.out.println("c = " + c);
}
}輸出
i = 5 c = A
現在讓我們來理解上面的程式。
上面程式中的關鍵字是`int`和`char`,它們分別指定整型和字元型資料型別。`i`和`c`是識別符號。
在上面的程式中,定義了`i`和`c`的值,然後列印它們。演示此程式碼片段的程式碼如下。
int i = 5;
char c = 'A';
System.out.println("i = " + i);
System.out.println("c = " + c);
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP