
모든 객체는 this 라는 키워드로 자신에 대한 참조를 엑세스할 수 있습니다.
특정 객체에 대해 인스턴스 메서드가 호출될 때 메서드의 본문은 this 키워드를 암시적으로 사용하여 객채의 인스턴스 변수 및 기타 메서드를 참조합니다.
this 참조를 암묵적으로 명시적으로 사용할 수 있습니다.
두 개 이상의 클래스가 포함된 .java 파일을 컴파일할 때 그 컴파일러는 모든 클래스에 대해 .class 확장자가 있는 별도의 클래스 파일을 생성합니다.
하나의 소스 코드(.java) 파일에 여러 클래스 선언이 포함된 경우 컴파일러는 해당 클래스의 두 클래스 파일을 같은 디렉토리에 배치합니다.
소스 코드 파일에는 private 클래스를 하나만 포함할 수 있으며, 그렇지 않으면 컴파일 오류가 발생합니다.
non-public 클래스들은 동일한 패키지에 있는 다른 클래스에서만 사용할 수 있습니다.
// Fig. 8.4: ThisTest.java
// this used implicitly and explicitly to refer to members of an object
public class ThisTest
{
public static void main(String[] args)
{
SimpleTime time = new SimpleTime(15, 30, 19);
System.out.println(time.buildString());
}
} // end class ThisTest
// class SimpleTime demonstrates the "this" reference
class SimpleTime
{
private int hour; // 0~23
private int minute; // 0~59
private int second; // 0~59
// if the constructur uses parameter names identical to
// instance variable names the "this" reference is
// required to distingish between the names
public SimpleTime(int hour, int minute, int second)
{
this.hour = hour; // set "this" object's hour
this.minute = minute; // set "this" object's minute
this.second = second; // set "this" object's second
}
// use explicit and implicit "this" to call toUniversalString
public String buildString()
{
return String.format("%24s: %s%n%24s: %s",
"this.toUniversalString()", this.toUniversalString(),
"toUniversalString()", toUniversalString());
}
// convert to String in universal-time format (HH:MM:SS)
public String toUniversalString()
{
// "this" is not required here to access instance variables
// because method does not have local variables with smae
// name as instance variables
return String.format("%02d:%02d:%02d",
this.hour, this.minute, this.second);
}
} // end class SimpleTime

대부분의 IDE들은 this.x = x 대신 x = x라고 말하면 경고를 발행하며, 이 문장은 종종 작동 금지라고 불립니다.
오버로드된 생성자를 사용하면 클래스의 개체를 다양한 방식으로 초기화할 수 있습니다.
생성자에 과부하를 걸려면 서명이 다른 여러 생성자 선언을 제공하기만 하면 됩니다.
컴파일러는 각 서명의 매개 변수 수, 매개 변수 유형 및 매개 변수 유형 순서에 따라 서명을 차별화한다는 점을 기억하세요.
Class Time2 에는 객체를 초기화하는 편리한 방법을 제공하는 5개의 오버로드된 생성자가 포함되어 있습니다.
컴파일러는 생성자 호출에 지정된 인수 유형의 수, 유형 및 순서를 각 컨스트럭터 선언에 지정된 매개변수 유형의 수, 유형 및 순서와 일치시켜 적절한 생성자를 호출합니다.