this();
자기 자신의 생성자를 호출하는 것이며, 호출하는 곳의 첫 번째 문장에 작성해야함.
this.
인스턴스 변수 자기자신과 매개변수(파라미터)로 들어오는 변수의 이름이 동일할 경우 구분을 위해서 사용
String str1 = "Simple String";
String str1 = new String("Simple String");
String str1 = "Simple String";
String str2 = "Simple String";
String str3 = new String("Simple String");
String str4 = new String("Simple String");
if(str1 == str2)
System.out.println("str1과 str2는 동일 인스턴스 참조");
else
System.out.println("str1과 str2는 다른 인스턴스 참조");
if(str3 == str4)
System.out.println("str3과 str4는 동일 인스턴스 참조");
else
System.out.println("str3과 str4는 다른 인스턴스 참조");
결과값
str1과 str2는 동일 인스턴스 참조
str3과 str4는 다른 인스턴스 참조
이유
str1과 str2는 스태틱으로 이미 올라간 공유된 메모리 주소값을 참조.
str3과 str4는 각각의 객체를 만드므로 다른 주소값 참조
String 객체에 있는 length() 와 함수와 charAt() 함수를 활용하시오.
입력:abcde
출력:edcba
String alpha = "abcde";
for (int a = alpha.length(); a > 0; a--) {
System.out.print(alpha.charAt(a - 1));
}