5. 11. 기본타입 참조타입
• 기본타입
– Pass(assign) by value, immutable(불변)
– public void make(int a)란 메소드가 있을때 make(2); 처럼 값을 넣
어서 메서드를 사용하는것은 패스바이밸류다.
– int a = 1; 이라고 했을 때 'a'가 바뀌지 않기 때문에 이것을
immutable이라 한다.
• 참조타입
– arr = [a][b][c] , arr[0] = d;는 주소값의 의한 변경.
– API, User Define, Array
6. 12. Method #1
public static void Main(String[] args){
…}
• public : 접근 제한자.
• ■ public : 어디서든지 접근가능. (UML에서는 + 로 사용한다)
• ■ protected : 상속을 하면 public, 상속을 안하면 private (UML : #)
• ■ private : 자기 class내에서만 public으로 사용 (UML : -)
• ■ default : 아무것도 안쓸때 사용됨
– protected와 비슷하지만 하위class에서 사용불가. (아무것도 안적음)
7. 13. Method #2
• static : 주소값을 가지냐 가지고 있지않은가?
• ■ Non-static :
• ■ static : 메인메서드는 시작과 끝이기 때문에
• # B b = new B()를 사용하지 않고도, 즉 객체를 생성하지 않고 B클래스내에
있는 public static void print() 메서드를 사용할 수 있다. - 이것은 어떤 객체를
생성시킬 필요가 없다.
•
• # public void print()로 메서드를 생성시켰을 때는 new로 주소를 할당하고 인
스턴스를 생성해야 메서드가 사용가능하다.
•
• # 규칙
• static -> static
• static -x-> public
• non-static -> static
• non-static -x-> non-static
8. 12. Method #3
• void : 리턴타입
• return isc == 1 ? true, false
• 클래스도 리턴타입이 될 수 있다.
• public B isLeafYear(int n){
• B b;
• if(n=1){ b = new B();
• return B;}
• }
9. 12. Method #4
• String[] arg : 매개변수(parameter)
– Int myMethod(String str){ …. }
• public void LeafYear(int i)에서 int i는
argment(호출시의 인수 )
– String buf = “hi”;
– String temp = mymethod(buf);
11. 13. String #2
• charAt
• public char charAt(int index)
• Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the
sequence is at index 0, the next at index 1, and so on, as for array indexing.If the char value specified by the index
is a surrogate, the surrogate value is returned.
• Specified by:charAt in interface CharSequence
• Parameters:index - the index of the char value.
• Returns:the char value at the specified index of this string. The first char value is at index 0.
• Throws:IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.
• String substring(int beginIndex)
Returns a new string that is a substring of this string.
• String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.