제어자(modifier)
- 클래스와 클래스의 멤버(멤버 변수, 메서드)에 부가적인 의미 부여
- 접근 제어자 : public, protected, (default), private
- 그 외 : static, final, abstract, native, transient, synchronized, volatile, strictfp
- 하나의 대상에 여러 제어자를 같이 사용 가능(접근 제어자는 하나만)
public class ModifierTest{
public static final int WIDTH = 200;
public static void main(String[] args){
System.out.println("WIDTH="+WIDTH);
}
}
static - 클래스의, 공통적인
class StaticTest{
static int width = 200;
static int height = 120;
static {
}
static int max(int a, int b){
return a > b ? a : b;
}
}
final - 마지막의, 변경될 수 없는
final class FinalTest{
final int MAX_SIZE = 10;
final void getMaxSize(){
final int LV = MAX_SIZE;
return MAX_SIZE;
}
}
abstract - 추상의, 미완성의
abstract class AbstractTest{
abstract void move();
}
AbstractTest a = new AbstractTest();