JAVA

C++ 프로그래머 Java 맛보기 #16

aucd29 2013. 9. 26. 21:07
java 에서 static 형태의 멤버 변수를 초기화 해보도록 하자 C++ 에서는 선언을 한 후 클래스 밖에서 초기화 값을 설정하던 것과 다르게 java의 static 변수는 선언과 함께 값을 디파인 할 수 있다.

java
public class BedAndBreakfast {
    public static int capacity = 10; //initialize to 10
    private boolean full = false; //initialize to false
}

C++
class BedAndBreakfast {
public
    static int capacity;
private:
    private bool full;
}
int BedAndBreakfast::capacity = 10;