Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 2
参照データ型 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 17
参照データ型
Javaの参照データ型は基本データ型以外全てです。基本データ型と異なり、参照データ型は変数にメモリ番地を格納します。
基本データ型の変数の代入は値の代入ですが、参照データ型の代入はメモリ番地の代入になります。
以下、参照データ型の例です。

参照データ型のラッパークラス
// Sampleクラス
public class Sample{
    private int a = -1;
    private int b = -1;

    public void setA(int a){
        this.a = a;
    }

    public void setB(int b){
        this.b = b;
    }

    public int getA(){
        return a;
    }

    public int getB(){
        return b;
    }
}

// TestMainクラス
public class TestMain{
    public static void main(String args[]) {
        Sample sp1 = new Sample();
        Sample sp2 = new Sample();

        sp1.setA(2);
        sp1.setB(3);
        System.out.println(sp1.getA());
        System.out.println(sp1.getB());

        sp2.setA(6);
        sp2.setB(7);
        System.out.println(sp2.getA());
        System.out.println(sp2.getB());
        
        // 参照データ型の代入
        sp1 = sp2;

        sp1.setA(10);// sp1の値をセット
        sp1.setB(11);// sp1の値をセット
        System.out.println(sp2.getA());// sp2の値を標準出力
        System.out.println(sp2.getB());// sp2の値を標準出力

        sp2.setA(20);// sp2の値をセット
        sp2.setB(21);// sp2の値をセット
        System.out.println(sp1.getA());// sp1の値を標準出力
        System.out.println(sp1.getB());// sp1の値を標準出力
    }
}
実行結果
2
3
6
7
10
11
20
21
実行結果は上記の通りになります。
sp1 = sp2;としているため、ここでsp1とsp2が指すメモリ番地が同じになります。
そのため、sp1.setA()メソッドはsp2.setA()メソッドを実行しているのと同じになります。
よって上記のような出力結果となります。

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 145

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 145

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 154

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/java/ref_data/ref_data.html on line 154