PL
 in
 Java
 
 
Week03
 
I n h e r i t a n c e
조영호
 
snatcher@nhn.com
 
상속
Conceptual Perspective
 
Implementation Perspective
 
객체지향
 
Object-Orientation
 
개념
 관점
 
구현
 관점
 
Conceptual Perspective
 
Implementation Perspective
 
객체지향
 
Object-Orientation
 
개념
 관점
 
구현
 관점
 
Type
 
Class
 
Conceptual Perspective
 
Implementation Perspective
 
객체지향
 
Object-Orientation
 
개념
 관점
 
구현
 관점
 
Generalization
 
Inheritance
 
To p i c s
 
Inheritance
Generalization
Composition
Method Overriding
super
super()
사람
 
요츠바
 
5살
 
class Person {	
String name;	
int age;	
	
Person() {	
this(사람, 1);	
}	
Person(String name, int age) {	
this.name = name;	
this.age= age;	
}	
String introduce() {	
return 이름 :  + name + , 나이  + age + 세;	
}	
}	
Person
 
Person yotsuba = new Person(요츠바, 5);	
System.out.println(yotsuba.introduce());
Person yotsuba = new Person(요츠바, 5);	
name = 요츠바
age = 5
 
Person
new Person()
 
킬러
 
class Killer {	
String name;	
int age;	
String warning;	
String weapon;	
Killer(String name, int age, String warning, 	
String weapon) {	
this.name = name;	
this.age = age;	
this.warning = warning;	
this.weapon = weapon ;	
}	
	
String introduce() {	
return 이름 :  + name + , 나이  + age + 세;	
}	
String getWeapon() {	
return weapon;	
}	
}	
Killer
 
Killer killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);	
System.out.println(killerYotsuba.introduce());	
System.out.println(killerYotsuba.getWeapon());
Killer killerYotsuba = new Killer(요츠바, 5, 	
You can tell me in hell., 총);	
name = 요츠바
age = 5
warning = You..
weapon = 총
 
Killer
new Killer()
 
Person  Killer
 
Person
 
name
age
 
introduce()
 
Killer
 
name
age
warning
weapon
 
introduce()
getWeapon()
 
Code Duplication
 
Person
 
name
age
 
introduce()
 
Killer
 
name
age
warning
weapon
 
introduce()
getWeapon()
 
Inheritance
 
Person
 
name
age
 
introduce()
 
Killer
 
warning
weapon
 
getWeapon()
 
class Killer extends Person {	
String warning;	
String weapon;	
Killer(String name, int age, String warning, String weapon) {	
this.name = name;	
this.age = age;	
this.warning = warning;	
this.weapon = weapon;	
}	
String getWeapon() {	
return weapon;	
}
}	
Killer extends Person
 
Person yotsuba = new Person(요츠바, 5);	
name = 요츠바
age = 5
 
Person
Killer killerYotsuba = new Killer(요츠바, 5, 	
You can tell me in hell., 총);	
name = 요츠바
age = 5
warning = You..
weapon = 총
 
Killer
Member Variable Inheritance
 
Person yotsuba = new Person(요츠바, 5);	
	
System.out.println(yotsuba.introduce());	
	
	
	
Killer killerYotsuba = new Killer(요츠바, 5, 	
You can tell me in hell., 총);	


System.out.println(killerYotsuba.introduce());	
System.out.println(killerYotsuba.getWeapon());	
Method Inheritacne
 
음악가
 
Person
Code Reuse
 
Inheritance
 
Person
 
name
age
 
introduce()
 
Musican
 
instrument
play()
 
public class Musician extends Person {	
String instrument;	
Musician(String name, int age, String instrument) {	
this.name = name;	
this.age = age;	
this.instrument = instrument;	
}	
String play() {	
return instrument +  연주;	
}	
}	
Musician extends Person
 
Musician musicanYotsuba = new Musician(요츠바, 5, 피리);	
System.out.println(musicanYotsuba.introduce());	
System.out.println(musicanYotsuba.play());
Code Reuse

[NHN NEXT] Java 강의- Week3