📂Java15_ControlStatementEx Ex4 ~ 📂Java20_Scope
읽은 바이트를 문자, 정수, 실수, 불리언, 문자열 등 다양한 타입으로 변환하여 리턴
import java.util.*;
public class MainClass {
public static void main(String[] args) {
// 키보드 입력
Scanner scanner = new Scanner(System.in);
// 정수
int a = scanner.nextInt();
// 문자열
String str = scanner.next();
// String str = scanner.nextLine();
scan.close();
}
}
📂Java15_ControlStatementEx
객체를 만들기 위한 설계도
public class MainClass {
public static void main(String[] args) {
// 클래스를 통해 객체를 생성
TestClass1 t1 = new TestClass1();
// t1에 저장되어 있는 객체의 ID를 t2에 저장
Testclass1 t2 = t1;
// 새로운 객체를 생성
TestClass1 t3 = new TestClass1();
}
}
// 클래스를 정의
class TestClass1 {
}
📂Java16_OOP_Basic
클래스에서의 작업의 단위
class TestClass {
// [접근 제한자] [리턴타입] 메서드 이름([매개변수])
public void testMethod() {
// 소스 코드
}
}
public void testMethod() {
for (int i = 0; i < 10; i++) {
if (i > 5) {
return;
}
System.out.println(i);
}
}
public int testMethod() {
System.out.println("testMethod6 호출");
return 100;
}
// 매개변수를 가지고 있는 메서드
public int testMethod(int a, int b) {
int c = a + b;
return c;
}
📂Java17_Method
객체를 통해 호출하는 변수, 객체 변수라고도 함
public class MainClass {
public static void main(String[] args) {
TestClass1 t1 = new TestClass1();
t1.testMethod1();
// 객체 참조 변수를 통한 멤버 변수 접근
System.out.printf("t1.memberA1 : %d\n", t1.memberA1);
}
}
class TestClass1 {
// 멤버 변수
int memberA1 = 100;
// 같은 클래스에 정의한 메서드에서 변수를 사용한다.
public void testMethod1() {
// 같은 클래스에 정의한 메서드 내에서는 멤버 변수의 접근이 자유롭고
// 변수의 이름만 작성하면 된다.
System.out.printf("memberA1 : %d\n", memberA1);
}
}
📂Java18_MemberVariable
객체에 접근하기 위해 사용하는 객체의 ID값을 가지고 있는 변수가 하나도 없다면 소멸의 대상
📂Java19_ObjectDestroy
📂Java20_Scope