分類
基本データ型(プリミティブ)
・byte, short, int, long, float, double, boolean, char
参照型:ポインタ
・String, Array(int[]), Class
例(1)
int[] a = {3, 5, 7}; int[] b = a; b[1] = 8; System.out.println(a[1]); System.out.println(b[1]);
実行結果は、「8 8」となる。
例(2)
String s = "hello"; String t = s; t = "world"; System.out.println(s); System.out.println(t);
実行結果は、「hello worldとなる。
文字列は変更不可であり、違う文字列を割り当てると別の領域に新しくデータを確保する。