Java(Class2)_Polymorphism_02

2024. 11. 1. 14:51·Java/기초 내용 정리

2024-11-01

 

 

 

 

 

car.tire >>> polymorphism.HanKookTire@6504e3b2
한국타이어가 회전을 합니다.

car.tire >>> polymorphism.KumHoTire@7b3300e5
금호타이어가 회전을 합니다.

 

package polymorphism;

public interface Tire {

	void roll();
}

 

package polymorphism;

public class HanKookTire implements Tire{

	@Override
	public void roll() {
	
		System.out.println("한국타이어가 회전을 합니다.");
	}
}

 

package polymorphism;

public class KumHoTire implements Tire {

	@Override
	public void roll() {
	
		System.out.println("금호타이어가 회전을 합니다.");
	}
}

 

package polymorphism;

public class Car {

	//  멤버변수
	Tire tire;		//  has a  개념.(객체생성의 개념은 아님.)
	
	void run() {
		
		tire.roll();
	}
}

 

package polymorphism;

public class Car_02 {

	public static void main(String[] args) {
		
		Car car = new Car();
		
		car.tire = new HanKookTire();
		//Tire tire = new HanKookTire();	과 동일.
		
		System.out.println("car.tire >>> " + car.tire);
		
		car.run();
		
		System.out.println();
		
		car.tire = new KumHoTire();
		//Tire tire = new KumHoTire();	과 동일.
		
		System.out.println("car.tire >>> " + car.tire);
		
		car.run();
	}
}

'Java > 기초 내용 정리' 카테고리의 다른 글

Java(Class2)_Access_01  (0) 2024.11.01
Java(Class2)_Polymorphism_03  (0) 2024.11.01
Java(Class2)_Polymorphism_01  (0) 2024.11.01
Java(Class2)_Exam_03  (0) 2024.10.31
Java(Class2)_Exam_02  (0) 2024.10.31
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(Class2)_Access_01
  • Java(Class2)_Polymorphism_03
  • Java(Class2)_Polymorphism_01
  • Java(Class2)_Exam_03
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Java(Class2)_Polymorphism_02
상단으로

티스토리툴바