Java15 4/8 - 상속, 인터페이스, 중첩 선언과 익명 객체 목차상속재사용코드 줄임유지보수성을 높임상위 그룹으로 한 번에 묶을 수 있음(그룹핑) → 통일성, 일관성자식 클래스에 extneds 키워드를 이용package ch07.sec02;public class Phone { public String model; public String color; public void bell() { System.out.println("벨이 울립니다."); } public void receiveVoice(String message) { System.out.println("자기: " + message); } public void sendVoice(String message) { System.out.println("상대방: " + message); } public void h.. 2025. 4. 12. 4/7 - 클래스 클래스객체지향 프로그래밍 (OOP)객체지향 프로그래밍의 특징상속 : 부모/자식캡술화 (encapsulation), 정보 은닉보안 (secure)안전 (safe)사용성 (useful)다형성 (polymophism)여러 자료형을 가질 수 있는 성질 → 하나의 실행문으로 다른 결과 도출클래스 (설계도) - 객체 (피조물)객체 생성자료형 변수명 = 값클래스 변수명 = new 클래스 () → 객체가 나옴클래스의 용도타입(종류) classification데이터 저장 (자료 구조)기능 보관 (파일, 폴더)생성자가 없다면 자바가 컴파일 시간에 기본 생성자 자동으로 생성기본 생성자 = 매개변수가 없는 생성자생성자를 만들어 줄 때에는, 변수명은 기재하지 않는다.리턴 타입이 없다.이름이 클래스명과 동일해야 한다.Studen.. 2025. 4. 12. 이것이 자바다 - 챕터5 연습 문제 8번 int[][] array = { { 95, 86 }, { 83, 92, 96 }, { 78, 83, 93, 87, 88 } }; int sum = 0; int cnt = 0; for(int i = 0; i9번 Scanner sc = new Scanner(System.in); int students = 0; int[] scores = null; while (true) { System.out.println("-----------------------------------------------"); System.out.println("1.학생수 | 2.점수입력 | 3.점수리스트 | 4.분석 | 5.종료"); System.out.println("---------------.. 2025. 4. 5. 이것이 자바다 - 챕터4 연습 문제 3번 // 3번 int sum = 0; for(int i =1;i4번 // 4번 while(true) { int one = (int)(Math.random() * 6 + 1); int two = (int)(Math.random() * 6 + 1); System.out.println("1 번째 : " + one); System.out.println("2 번째 : " + two); if(one + two == 5) { System.out.println("주사위 합 : " + (one + two)); break; } } 5번// 5번 for(int i = 0; i6번// 6번 for(int i=0;i7번// 7번 int money = 0; .. 2025. 4. 5. 이것이 자바다 - 챕터3 연습 문제 3번 - 학생 1명의 연필 수와, 남은 연필 수 구하기int pencils = 534; int students = 30; int pencilsPerStudent = pencils / students; System.out.println(pencilsPerStudent); int pencilsLeft = pencils % students; System.out.println(pencilsLeft);4번 - 십의 자리 이하를 버리는 코드 만들기 (산술 연산자만 사용)int value = 356; System.out.println(value - value%100); 2025. 4. 5. 4/4 공부 기록 - 참조 타입, 클래스 객체 지향 프로그래밍참조 자료형대입을 해도 참조 값이 대입 된다.public static void main(String[] args) { //기본 자료형 int a = 10; int b = a; a = 11; System.out.println(b); 출력 : 10 // a의 값이 올바르게 바뀐 것으 ㄹ알 수 있다. //참조 자료형 int[] a1 = {1,2,3}; int[] b1 = a1; System.out.println(Arrays.toString(b1)); a1[0] = 4; System.out.println(Arrays.toString(b1)); 출력 [1, 2, 3] [4, 2, 3] // b1의 배열도 바뀌었다. }객체 비교는 =.. 2025. 4. 5. 이전 1 2 3 다음 728x90 반응형