오늘의 코딩
: 오늘 것을 익혀야 객체 묶음을 익힐 수 있다!
순서
ch07_ex03>>
- Computer
- ComputerEx
ch08_ex01>>
- Lenderable: 키워드(abstract 추상 메소드), 전날 OverRide3 참고, Interface는 implement, class는 extends
package ch08_ex01;
public interface Lenderable {
//인터페이스에서는 변수를 쓸 수 없다
int BORROW = 1;
int NORMAL = 0;
abstract void checkOut(String borrower, String date);
void checkin();
}
//abstract를 사용했기 때문에 아래는 전부 추상 Method
class SeperateVolume implements Lenderable {
//Interface는 implement, class는 extends
String title;
String date;
int borrower;
int status;
SeperateVolume (String title) {
this.title = title; //this로 인해 초기화
}
public void checkOut(String borrower, String date) {
//checkOut: NORMAL일때만 책 대여해주는 메소드
// NORMAL ++;
if (status != NORMAL) return;
this.date = date;
this.borrower = BORROW; //-->수정하라고 뜨면 ctrl누르고 위에거 누르기
// BORROW = 1; 안됨
System.out.println(borrower + "가 " +date+ "일에" +title+"을 대여했다");
}
@Override
public void checkin() {
//checkin: BORROW일 떄만 책 반납하는 메소드
if (status !=BORROW) return;
System.out.println(borrower +"가 " +title+ "을 반납했다");
date = null;
title = null;
status = NORMAL;
}
}
이름 | 정의 및 활용 |
interface | 선생님의 설명: 다 추상적임 정의: 극단적으로 동일한 목적 하에 동일한 기능을 수행하게끔 강제하는 명령 목적: 자바의 다형성을 극대화하여 개발코드 수정을 줄이고 프로그램 유지 보수성을 높이기 위해 사용 |
⭐abstract | interface와의 차이점 꼭 알아두기(0531 일지 참조) |
implement | 추상적인 interface를 구현해줌 |
extends | 선생님의 설명: 부모 메소드(class)에게 상속받은 뒤 없는 것을 확장시켜주는 역할 |
Association관계 (연관관계) |
한 객체가 다른 객체와 연결되어 있음을 나타낼 때 그들을 연관관계로 지칭함 ex)knifeActionRobot |
instanceof | 선생님의 설명: 객체의 Type을 비교할 때 쓰임 객체가 어떤 클래스인지, 어떤 클래스를 상속받았는지 확인하는데 사용하는 연산자 이다.즉, 참조변수가 참조하고 있는 인스턴스의 실제 타입을 알아보기 위해 해당 연산자를 사용한다. ex1) true false 할 때 사용 ex2) ch08+ex01_Robot참조>>> r의 객체Type가 DanceRobot인지 물을때 사용 |
OverLoading | 선생님의 설명: 하나의 클래스에 여러개의 메소드가 파라메터나 유형 따라 들어가는 것? |
//instanceof 예시
class A { }
class B extends A { } // A 클래스를 상속
public static void main(String[] args) {
A a = new A();
B b = new B();
System.out.println(a instanceof A); // true 출력
System.out.println(b instanceof A); // true 출력 : A를 상속 받았기 때문
System.out.println(a instanceof B); // false 출력
System.out.println(b instanceof B); // true 출력
- LenderableEX
- Inter01: interface란?> 05_31일지 참조
1) 양식의 역할을 하면 그 역할이 큼
2) 다중상속 지원 (극히 일부분)
3) ⭐⭐⭐class와 class 를 연결해줌 - Inter01EX>>> Static Final
- Inter02EX
- Inter03EX
- (interface파일)Robot
- RobotEx
- Shape + ShapeEx
- Volume + VolumeEx
ch08_ex02>>
- Super01
- Super02
- Super03>>> 기사 실기시험에 나올 수 있
- Engine
- Car>>> Association관계, Engine과 Car 관계 복습하기
오늘의 과제
ch08_ex01>>
- Shape + ShapeEx >> OverRide3, Inter01,Robot참고
- Volume + VolumeEx>>
'Java' 카테고리의 다른 글
2024_06_04_화 (0) | 2024.06.04 |
---|---|
2024_06_03_월 (0) | 2024.06.03 |
2024_05_31_금 (0) | 2024.05.31 |
2024_05_29_수 (0) | 2024.05.29 |
2024_05_28_화 (0) | 2024.05.29 |