Microsoft PowerPoint - lec08_1311.ppt [호환 모드]

Similar documents
JAVA PROGRAMMING 실습 08.다형성

PowerPoint Presentation

자바 프로그래밍

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

Microsoft PowerPoint - 2강

PowerPoint Presentation

PowerPoint 프레젠테이션

gnu-lee-oop-kor-lec06-3-chap7

ch09

클래스와객체 필드 메소드 중첩클래스 자료추상화 [2/35]

PowerPoint 프레젠테이션

No Slide Title

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

Design Issues

PowerPoint Presentation

JAVA PROGRAMMING 실습 07. 상속

PowerPoint Presentation

PowerPoint Presentation

01-OOPConcepts(2).PDF

PowerPoint 프레젠테이션

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

5장.key

JAVA PROGRAMMING 실습 02. 표준 입출력

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345])

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

제11장 프로세스와 쓰레드

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

쉽게 풀어쓴 C 프로그래밍

오버라이딩 (Overriding)

Microsoft PowerPoint - Java7.pptx

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

C++ Programming

Microsoft PowerPoint - Lect04.pptx

슬라이드 1

Microsoft PowerPoint - java2 [호환 모드]

Microsoft PowerPoint - chap11

JAVA PROGRAMMING 실습 05. 객체의 활용

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

슬라이드 1

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

비긴쿡-자바 00앞부속

09-interface.key

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Microsoft PowerPoint - additional07.ppt [호환 모드]

PowerPoint Presentation

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

PowerPoint 프레젠테이션

Microsoft PowerPoint - 6주차.pptx

슬라이드 1

설계란 무엇인가?

PowerPoint 프레젠테이션

Microsoft PowerPoint - Chapter 6.ppt

Microsoft Word - EEL2 Lab4.docx

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - CSharp-10-예외처리

PowerPoint Template

JAVA PROGRAMMING 실습 09. 예외처리

PowerPoint 프레젠테이션

쉽게 풀어쓴 C 프로그래밍

슬라이드 1

1

JVM 메모리구조

Microsoft PowerPoint - additional08.ppt [호환 모드]

쉽게 풀어쓴 C 프로그래밍

Network Programming

05-class.key

PowerPoint Presentation

Cluster management software

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

PowerPoint Presentation

PowerPoint Presentation

Slide 1

소프트웨어공학개론 강의 5: 객체지향개념 최은만동국대학교컴퓨터공학과

Microsoft PowerPoint 장강의노트.ppt

쉽게

Chapter 6 Objects and Classes

No Slide Title

PowerPoint Presentation

Microsoft PowerPoint - lec12 [호환 모드]

PowerPoint Presentation

Microsoft PowerPoint - 04_OOConcepts(2010).pptx

Microsoft PowerPoint - java1 [호환 모드]

슬라이드 1

제8장 자바 GUI 프로그래밍 II

PowerPoint Template

C# 입문 : 이론과 실습

PowerPoint 프레젠테이션

JAVA PROGRAMMING 실습 02. 표준 입출력

ThisJava ..

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

Microsoft PowerPoint - 13_UMLCoding(2010).pptx

Spring Data JPA Many To Many 양방향 관계 예제

Microsoft PowerPoint - additional01.ppt [호환 모드]

Transcription:

JAVA 프로그래밍 8. 확장클래스및인터페이스 한동일 학습목표 To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package access control To learn about interfaces To be able to convert between class and interface references 2/62

학습목표 To learn how to implement helper classes as inner classes To understand how inner classes access variables from the surrounding scope To implement event listeners for timer events 3/62 확장클래스 (extended class) 확장클래스의개념 기존클래스 superclass (base class) 추가정보 subclass (derived class) 확장클래스 상속 (Inheritance) superclass 의모든속성이 subclass 로전달되는기능 클래스의재사용성을증가시킨다. 4/62

상속의예 person 상위 (super) 클래스 student faculity staff undergrad graduate 하위 (sub) 클래스 5/62 확장클래스 확장클래스정의형태 class SubClassName extends SuperClassName { // 필드선언 // 메소드정의 확장클래스의예 : class SuperClass { int a; void methoda { //... class SubClass extends SuperClass { int b; void methodb { //... 6/62

확장클래스 확장클래스의실제예 : Example: public class SavingsAccount extends BankAccount { public SavingsAccount(double rate) { interestrate tr t = rate; public void addinterest() { double interest = getbalance() * interestrate / 100; deposit(interest); private double interestrate; Purpose: To define a new class that inherits from an existing class, and define the methods and instance fields that are added in the new class. 7/62 확장클래스 단일상속 (single inheritance) 오직한개의슈퍼클래스만가질수있다. C++ : 다중상속 (multiple inheritance) 지원 Object 클래스 모든클래스의슈퍼클래스 객체에적용할수있는기본메소드가정의되어있음 Object 슈퍼클래스를명시하지않으면기본적으로슈퍼클래스는 Object SuperClass SubClass 8/62

확장클래스의메소드 메소드재정의 (method overriding) ) 슈퍼클래스에정의된메소드의의미를서브클래스에서변경 슈퍼클래스의메소드를상속 (inherit) 명시적으로재정의하지않을경우자동으로상속 새로운메소드의추가 슈퍼클래스에서정의되지않은메소드를새로추가하여사용 9/62 메소드중복 메소드중복 (method overloading) 메소드이름은같은데매개변수의개수와형이다른경우 void methodover(int i) { /*... */ // 첫번째형태 void methodover(int i, int j) { /*... */ // 두번째형태 메소드가중복된경우, 호출시구별은컴파일러가행함. 시그니처 (signature) 메소드를구별하는데쓰이는정보 메소드의이름 매개변수의개수 매개변수의형 10/62

메소드재정의 메소드재정의 (method overriding) ) 슈퍼클래스에정의된메소드의의미를서브클래스에서변경 매개변수개수와형이같음 --- 같은메소드 서브클래스의메소드로대체 메소드재정의를할수없는경우 정적 (static) 메소드 최종 (final) 메소드 최종클래스내에있는모든메소드는묵시적으로최종메소드 11/62 메소드중복과재정의예 SchoolFamily id name 메소드오버로드 상속 Teacher SchoolFamily(int id) SchoolFamily(int id, String name) public void register(int id, String name) 메소드 드오버라이드 상속 Student course 드 lesson,studentnum,total,average Teacher(int course, int id) { super(id); Teacher(int course, int id, String name) { super(id, name); 12/62 Student(int studentnum, int kor, int eng, int math); total(); average(); public void register(int id, String name) { this.id = id; this.name = name; System.out.println(" 수강과목의수는? ");...

슈퍼클래스의메소드사용 확장클래스에서재정의된경우슈퍼클래스에서정의된메소드를부르고싶어도확장클래스의메소드가자동적으로불려짐 슈퍼클래스메소드를사용할경우 : super 이용 super.methodname(parameters) Example: public void deposit(double amount){ transactioncount++; super.deposit(amount); Purpose: To call a method of the superclass instead of the method of the current class 13/62 확장클래스의구성자 형태와의미는모두클래스구성자와같다. 단, 슈퍼클래스를초기화하기위해서는먼저슈퍼클래스 구성자를호출한다. super(), super(param1, param2, ) 슈퍼클래스의구성자를명시적으로호출 확장클래스구성자의첫문장에와야함 명시적으로호출하지않으면, 기본생성자가컴파일러에 의해자동적으로호출 14/62

다른이름 확장클래스의필드 그대로상속된다. 동일한이름 숨겨진다. super --- 숨겨진슈퍼클래스에있는필드를참조할때사용. 사용시주의할것 class SuperClass { int a = 1; int b = 1; class SubClass extends SuperClass { int a = 2; int b = super.a; //... 15/62 super.a super.b a b 확장클래스의필드 비공개필드 (private) 의접근 서브클래스는슈퍼클래스의비공개필드를직접접근불가능 서브클래스는슈퍼클래스의비공개필드를상속받아보유하고있지만접근은불가능 슈퍼클래스의비공개필드접근방법 슈퍼클래스의공개메소드이용 public void deposit(double amount){ transactioncount++; super.deposit(amount);// balance = balance + amount; // balance 는 private 이므로직접접근불가 16/62

속성변수의접근한정자 ( 복습 ) 접근한정자, 접근명세 (access specifier) 다른클래스에서필드의접근허용정도를나타내는부분 public, protected, private 접근한정자 private [ ] protected public 클래스 서브클래스 같은패키지 모든클래스 O X X X O O X O O O X X O O O O 선언예 private int i; // private int j; protected int k; // protected public int sum; // public 17/62 클래스타입변환 서브클래스의참조는슈퍼클래스참조로변환가능 SavingsAccount collegefund = new SavingsAccount(10); BankAccount anaccount = collegefund; Object anobject = collegefund; 모든참조는 Object 타입으로변환가능 18/62

클래스타입변환 슈퍼클래스참조로변환시참조객체에대해모르는부분발생 anaccount.deposit(1000); // OK anaccount.addinterest(); // No--not a method of the class to which h anaccount belongs 참조를변환하는경우 슈퍼클래스만알고서브클래스를모르는코드의재사용을위해 참조가가리키는객체는모든정보를보유 그러나변환된참조는모든정보를알지못함 19/62 클래스타입변환 슈퍼클래스의참조를서브클래스참조로변환시 반드시캐스팅사용 잘못된참조로변환시예외발생 주의요망 BankAccount anaccount = (BankAccount) anobject; 안전한처리방법 :i instanceof 연산자사용 instanceof 연산자 : 객체가특정타입에속하는지를판단 if (anobject instanceof BankAccount) { BankAccount anaccount = (BankAccount) anobject;... 20/62

instanceof 연산자 연산자의왼쪽에있는객체가오른쪽에있는객체형의인스턴스일경우에참값, 아닐경우거짓값을반환 형태 : 객체 instanceof 객체형 o instanceof C 가참값을반환할조건 객체 o 를생성한클래스 C 가 C 이거나 C 의하위클래스 C 가인터페이스일경우 C 는 C 를구현 C가 T 형의배열이고 o가 T형의배열일경우, T는 T 의하위인터페이스이거나하위클래스, 또는 T 와T가같은자료형 21/62 추상클래스 (abstract class) 추상메소드 (abstract method) 를갖고있는클래스 추상메소드 : 실질적인구현을갖지않고메소드선언만있는경우 선언방법 abstract class AbstractClass { public abstract void methoda(); void methodb() { //... 22/62

추상클래스 (abstract class) Wolf awolf = new Wolf(); Animal ahippo = new Hippo(); awolf Wolf Wolf 객체 ahippo Hippo 객체 Animal anim = new Animal();?? Animal 객체 Animal anim 23/62 Animal 추상클래스 (abstract class) 추상 Animal 추상 Polygon의면적은? Polygon 추상 Feline 추상 Canine Triangle Circle Rectangle Square Lion Hippo Cat Tiger Dog Wolf 24/62

추상클래스 (abstract class) 구현되지않고, 단지외형만을제공 추상클래스는객체를가질수없음 다른외부클래스에서메소드를사용할때일관성있게다루기위한방법을제공 다른클래스에의해상속후사용가능 서브클래스에서모든추상메소드를구현한후에객체생성가능 추상메소드를서브클래스에서구현할때접근한정자는항상일치 25/62 내부클래스 (Inner class) 클래스의내부에서정의된클래스 클래스내부에서사용하고자하는객체형을정의할수있는방법을제공 클래스의참조범위를제한하여클래스의이름충돌문제를해결 정보은닉화 (information hiding) class OuterClass { //... class InnerClass { //... 26/62

내부클래스 클래스내부나메소드내부에존재가능 지역변수의영역정의에의해서내부클래스를포함하는영역의지역변수를접근가능 단, 내부클래스주변의지역변수는 final로선언되어야내부클래스내에서접근가능 class OuterClassName { method signature {... class InnerClassName { // methods // fields...... class OuterClassName { // methods // fields class InnerClassName { // methods // fields... 27/62 내부클래스 (Inner class) 이름참조 OuterClass 내부 : InnerClass 단순명을사용 OuterClass 외부 : OuterClass.InnerClass public static void main(string[] args) { OuterClass outobj = new OuterClass(); OuterClass.InnerClass inobj = outobj.new InnerClass(); 접근수정자 public, private, protected static 존재유무에따라정적 / 비정적내부클래스로구분 내포클래스 (Nested Class) 라고도함 28/62

정적내부클래스 정적내부클래스 지정어 static을사용하여정의 정적변수사용가능 내부클래스를포함하는영역의정적변수접근가능 class OuterClass { //... static class InnerClass { static int staticvariable; //... 객체생성없이참조 OuterClass.InnerClass OuterClass.InnerClass inobj = new OuterClass.InnerClass(); 29/62 비정적내부클래스 비정적내부클래스 static 으로선언되지않은내부클래스 정적변수사용불가 class OuterClass { //... class InnerClass { //... 객체를생성한후멤버접근 30/62

내부클래스 컴파일시모든클래스에대해 *.class 파일을생성 명칭의형태 : 외부클래스이름 $ 내부클래스이름 자바소스 자바컴파일러 클래스이름.class 외부클래스이름 $ 내부클래스이름.class class Outer { class Inner1 { class Inner2 { // //... //... Outer.class Outer$Inner1.class Outer$Inner1$Inner2.class 31/62 인터페이스 (Interface) 란? 사용자접속을기술하는방법으로메소드들을선언하고필요한상수들을정의한프로그래밍단위 상수와구현되지않은메소드들만을갖고있는순수한설계의표현 다중상속 (multiple inheritance) 문제해결 단일상속 (single inheritance) --- 클래스 32/62

다중상속 Pet Animal Feline Canine Lion Hippo Cat Tiger Dog Wolf 33/62 다중상속의문제 다중상속 (multiple l inheritance) it 의문제점 죽음의다이아몬드 DigitalRecorder int i burn() CDBurner DVDBurner burn() burn() 자바에서는다중상속을허용하지않습니다. ComboBurner burn() 34/62

다중상속문제의해결 Robot 인터페이스 Pet Animal Agent RoboDog Feline Canin e Lion Hippo Cat Tiger Dog Wolf 35/62 인터페이스선언 선언형태 [public] interface InterfaceName [extends ListOfSuperInterfaces] // constant definitions // method declarations 사용예 interface BaseColors { int RED = 1; int GREEN = 2; int BLUE = 4; void setcolor(int color); int getcolor(); 36/62

인터페이스선언 인터페이스의필드 내부적으로상수를의미하는 static, final 의속성 선언된모든필드는반드시초기화 구현된 class 나객체를통해접근 실체필드는가질수없음 interface BaseColors { int RED = 1; int GREEN = RED + 1; int BLUE = GREEN + 2; void setcolor(int color); int getcolor(); 37/62 인터페이스선언 인터페이스의메소드 추상 (abstract) 속성 내부적으로추상메소드가됨 인터페이스의모든메소드를구현하지않는클래스는추상클래스로선언 내부적으로모두 public 메소드 static 이올수없음 생성자를갖지않음 38/62

인터페이스선언 일단, 인터페이스가선언되면인터페이스를구현하는클래스가있어야한다. 인터페이스는객체를가질수없다. class ClassName implements InterfaceName { // 인터페이스에서정의된메소드의구현 39/62 인터페이스확장 확장형태 [public] interface InterfaceName extends ListOfSuperInterfaces { // constant definitions // method declarations 확장예 interface RainbowColors extends BaseColors { int YELLOW = 3; int ORANGE = 5; int INDIGO = 6; int VIOLET = 7; void printcolor(int color); 40/62

인터페이스확장 인터페이스의다중상속 슈퍼인터페이스 2... 슈퍼인터페이스 1 슈퍼인터페이스 n 서브인터페이스 41/62 인터페이스확장 다중상속예 interface RainbowColors { int YELLOW = 1; // interface PrintColors { int YELLOW = 2; // interface ManyColors extends RainbowColors, PrintColors { int VERMILION = 3; int CHARTUSE = RED + 90; 다중상속시동일한이름의상수를상속 단순명은 ambiguous 하기때문에에러 RainbowColors.YELLOW, PrintColors.YELLOW 42/62

인터페이스확장 메소드상속 overloading, overriding 그러나, 시그니처가같고복귀형이다르면에러 메소드상속예 interface BaseColors { //... void setcolor(int color); int getcolor(); ` interface ActionColors extends BaseColors { void setcolor(int color) ; // overriding void setcolor(int red, int green, int blue) ; // overloading // Color getcolor(); // 에러 43/62 인터페이스구현 클래스를통하여구현된후객체를가짐 구현형태 public, final, abstract [modifier] class ClassName implements InterfaceName { // fields // methods // 인터페이스구현 44/62

구현예 인터페이스구현 class Color implements BaseColors { // fields public void setcolor(int color) { // public int getcolor() { // interface BaseColors { int RED = 1; int GREEN = RED + 1; int BLUE = GREEN + 2; void setcolor(int color); int getcolor(); 45/62 인터페이스구현 인터페이스에있는모든메소드들을구현하지않으면그클래스는추상클래스가된다. abstract class SetColor implements BaseColors { // fields public void setcolor(int t color) { // getcolor(); 에대한구현이없을경우 46/62

인터페이스구현 클래스확장과동시에인터페이스구현 class ClassName extends SuperClass implements ListOfInterfaces { // fields // methods 다이아몬드상속 (diamond inheritance) interface W { interface X extends W { class Y implements W { class Z extends Y implements X { X W Y Z 47/62 인터페이스 vs. 추상클래스 인터페이스 다중상속을지원 메소드선언만가능 --- 메소드를정의할수없다. 추상클래스 단일상속 메소드의부분적인구현이가능 48/62

클래스 / 인터페이스타입변환 클래스타입에서인터페이스타입으로의전환 클래스가인터페이스타입을구현시가능 public class BankAccount implements Measurable { // Other BankAccount methods public double getmeasure() { // Method implementation i BankAccount account = new BankAccount(10000); Measurable x = account; // OK // x 라는참조변수가참조하는객체가 getmeasure 라는메소드 // 를보유하고있다는사실만알수있음 49/62 클래스 / 인터페이스타입변환 관계없는타입사이의전환은불가능 Measurable x = new Rectangle(5, 10, 20, 30); // ERROR 인터페이스타입에서클래스타입으로의전환 반드시캐스트를사용해야함 인터페이스의참조가실제로는객체참조일경우만가능 BankAccount account = new BankAccount(10000); Measurable x = account; // 인경우... BankAccount otheraccount = (BankAccount) x; // OK 50/62

타이머이벤트처리 javax.swing.timer 클래스 : 균일한시간간격의이벤트발생 객체를규칙적인간격으로갱신할때유용 타이머는일정한간격의이벤트발생 이벤트발생시 ActionLister t 에게통보됨 ActionListener 인터페이스의구현필요 public interface ActionListener { void actionperformed(actionevent event); 51/62 타이머이벤트처리 ActionListener t 인터페이스의구현예 class MyListener implements ActionListener t { void actionperformed(actionevent event){ // This action will be executed at each timer event //Place listener action here 52/62

타이머이벤트처리 타이머이벤트처리순서 ActionListener 인터페이스를구현하는클래스정의 청취자객체구성 타이머구성자에게전달 타이머가동 프로그램을살려놓기위해대화상자를디스플레이 // ActionListener 구현 : 앞페이지참고 MyListener listener = new MyListener(); // 객체구성 Timer t = new Timer(interval, listener); // Timer 구성자 t.start(); // 타이머가동 JOptionPane.showMessageDialog(null, Quit? ); 53/62 [ 실습 0] Instanceof 연산자 첨부된 Instance 폴더내의 Instance.java 파일을이해하고수행이전에결과를예측해보라. 이후결과를확인해보라. 원하는결과가나오지않았다면이유를확인하라. 54/62

[ 실습 1] Overloading/Overriding idi 첨부된 Overloading 폴더내의 SubClass.java 와 OverloadingTest.java 를보고실행결과를예상하라. 예상한결과와다르다면왜그런지파악하라. SubClass.java 의 function 들을분류하라. Overriding과 Overloading Overloading의종류 SubClass.java 의주석을풀고실행하라. 원하는결과가나오는가? 나오지않는다면왜그런지파악하라. 55/62 [ 실습 2] Class 의확장 첨부된 Extends 폴더내의 Subtractor.java 코드등을이해하고 CalculatorTest.java를실행하여 Adder class 와의상속관계에대해파악하라. left와 right 변수를 protected로선언한이유는무엇인가? left 와 right 변수를단순히 private 로선언하면그증상은? left와 right 변수를 private로선언하고코드가동작하도록재설계를하라. 힌트 : getleft() 와같은공개인터페이스사용 Subtractor class 를상속하고곱하기와나누기를할수있게 Calculator class 를구현하고테스트하라. 56/62

[ 실습 3] Abstract Class 첨부된 Abstract 폴더내의 DrawTest.java 코드는사각형, 원, 삼각형그리고집모양을그리는코드의테스트파일이다. 여러번실행해보고어떻게동작하는지파악하라. 그후 DrawComponent.java 코드를통해서동작을이해하라. Drawable.java 코드를보고 DrawRectangle/Circle/ Triangle/House 코드가각각어떻게상속을사용하였는지확인하라. 4장에서구현한 Car.java 코드를활용하여 Drawable의상속을받게하고 5개 ( 사각형, 원, 삼각형, 집, 자동차 ) 의모양을랜덤하게그리도록코드를수정하라. 57/62 [ 실습 4] - Interface 첨부된 Interface 폴더내의 Calculator.java 는 calculate 라는추상메소드를가진추상클래스이다. Adder, Subtractor, Multiflier, Divider가오버라이딩하고있는것을확인하라. CalculatorTest.java 코드를통해원하는대로동작하는지확인하라. 클래스확장을인터페이스구현으로바꿔보라. Abstract Class 와 Interface 의차이점에유의할것. 58/62

[ 실습 5] 다중상속 첨부된 Multiple 폴더내의Dog.java 코드는 Animal과 Pet을상속받는클래스이다. DogTest.java 코드를검토해보고결과를예측한후실행하라. 원하는결과가나오지않았다면왜그런지생각해보라. interface를이용하여다중상속을받을수있게코드들을수정하라. 있으니까실습코드만들긴했지만다중상속은웬만하면쓰지말자 - 59/62 [ 실습 6] Timer event 첨부된 TimerTester는 1초 (1000ms) 마다현재시간을출력하는프로그램이다. 타이머와 ActionListener 의관계를중심으로이해하라. 시간을 10 초출력하면더이상출력하지않게수정하라. 60/62

[ 실습 7] Animation 첨부된 Car 폴더내의클래스들은움직이는자동차를출력하는프로그램이다. Car.java 코드의경우 4강에서구현한자동차그림에위치정보를얻는메소드가추가되어있으며이를이해하라. CarMoverComponent.java 코드의경우 001 0.01 초마다새로운위치에자동차를그리는동작을수행하며이를이해하라. 자동차가프레임윈도우바깥으로빠져나가지않도록코드를수정하라. 힌트 1: 프레임의왼쪽끝이나오른쪽끝, 위, 아래로나갈경우진행방향을변경 힌트 2 : Component( 혹은 JComponent) 클래스에서정의된 getwidth(), getheight() 메소드사용권장 61/62 Reading Assignment 9 강강의자료 ( 이벤트처리 ) 읽어올것. 62/62