LoginSignup
2
2

More than 5 years have passed since last update.

JAVA import static宣言

Posted at

import staticを使うことで、CURRENTという省略した指定が可能になる

▪️Test92.java

import B.Test92accountType;
import static B.Test92accountType.CURRENT;
import static B.Test92accountType.TERM;

public class Test92 {
    private String accountNo;
    private Test92accountType accountType;
    private int balance;

    public Test92(String accountNo, Test92accountType accountType) {

    }

    public static void main(String[] args) {
        Test92 customer = new Test92("12345", Test92accountType.ORDINALLYSAVINGS);
        Test92 customer2 = new Test92("21456", CURRENT);
        Test92 customer3 = new Test92("33332", TERM);
        Test92 customer4 = new Test92("77772", Test92accountType.TERM);
    }
}

▪️Test92accountType.java

package B;

public enum Test92accountType {
    // 指定した種類の値だけ入れることができる列挙型を定義
    ORDINALLYSAVINGS, CURRENT, TERM;
}

▪️Test92.java 実行結果

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2