46. 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
47.
Person yotsuba = new Person(요츠바, 5);
System.out.println(yotsuba.introduce());
53. 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
54.
Killer killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);
System.out.println(killerYotsuba.introduce());
System.out.println(killerYotsuba.getWeapon());
55. Killer killerYotsuba = new Killer(요츠바, 5,
You can tell me in hell., 총);
name = 요츠바
age = 5
warning = You..
weapon = 총
88. 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
273. class Person {
String name;
int age;
...
String introduce() {
return 이름 : + name + , 나이 + age + 세;
}
}
Person yotsuba = new Person(요츠바, 5);
name = 요츠바
age = 5
274.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
class
Object
superclass
String
toString()
{
...
}
278. class Person {
String introduce() {
return 이름 : + name + , 나이 + age + 세;
}
}
name = 요츠바
age = 5
279.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
class
Object
superclass
String
toString()
{
...
}
yotsuba.introduce()
280. class
Person
{
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
}
name = 요츠바
age = 5
281.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
class
Object
superclass
String
toString()
{
...
}
yotsuba.toString()
282. class Killer extends Person {
}
class Person {
String introduce() {
return 이름 : + name + , 나이 + age + 세;
}
}
Person yotsuba = new Killer(요츠바, 5,
You can tell me in hell., 총);
name = 요츠바
age = 5
warning = You..
weapon = 총
283.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
class
Object
superclass
String
toString()
{
...
}
class
Killer
superclass
285.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
class
Object
superclass
String
toString()
{
...
}
class
Killer
superclass
yotsuba.introduce()
class
Killer
extends
Person
{
}
class
Person
{
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
}
287.
this
class
Person
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
superclass
String
toString()
{
...
}
class
Killer
superclass
yotsuba.introduce()
String
introduce()
{
return
"무기 :
+
weapon
+
,
+
이름 :
+
name
+
,
나이
+
age
+
세;
}
class Killer extends Person {
String introduce() {
return "무기 : + weapon + , +
이름 : + name + , 나이 + age + 세;
}
}
class Person {
String introduce() {
return 이름 : + name + , 나이 + age + 세;
}
}
class
Object
308. public class Person {
String message() {
return Message : [ + introduce() + ];
}
String introduce() {
return 이름: + name + , 나이: + age + 세;
}
}
public class Killer extends Person {
String introduce() {
return "무기 : + weapon + , + 이름 : + name + , 나이 + age + 세;
}
}
Quiz
Person killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);
killerYotsuba.message();
310.
this
class
Person
String message() {
return Message : [ +
introduce() + ];
}
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
superclass
String
toString()
{
...
}
class
Killer
superclass
String
introduce()
{
return
"무기 :
+
weapon
+
,
+
이름 :
+
name
+
,
나이
+
age
+
세;
}
Person killerYotsuba = new Killer(요츠바, 5,
You can tell me in hell., 총);
killerYotsuba.message(); class
Object
this부터
315.
this
class
Person
String message() {
return Message : [ +
introduce() + ];
}
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
superclass
String
toString()
{
...
}
class
Killer
superclass
String
introduce()
{
return
"무기 :
+
weapon
+
,
+
이름 :
+
name
+
,
나이
+
age
+
세;
}
Person killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);
killerYotsuba.message();
class
Object
introduce()
317.
this
class
Person
String message() {
return Message : [ +
introduce() + ];
}
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
superclass
String
toString()
{
...
}
class
Killer
superclass
String
introduce()
{
return
"무기 :
+
weapon
+
,
+
이름 :
+
name
+
,
나이
+
age
+
세;
}
Person killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);
killerYotsuba.message();
class
Object
introduce()
this부터
322.
this
class
Person
String message() {
return Message : [ +
introduce() + ];
}
String
introduce()
{
return
이름 :
+
name
+
,
나이
+
age
+
세;
}
class
superclass
String
toString()
{
...
}
class
Killer
superclass
String
introduce()
{
return
"무기 :
+
weapon
+
,
+
이름 :
+
name
+
,
나이
+
age
+
세;
}
Person killerYotsuba = new Killer(요츠바, 5, You can tell me in hell., 총);
killerYotsuba.message();
class
Object
introduce()
this부터
333. public class Person {
String introduce() {
return 이름: + name + , 나이: + age + 세;
}
}
public class Killer extends Person {
String introduce() {
return "무기 : + weapon + , + 이름 : + name + , 나이 + age + 세;
}
}
Code Duplication
334. public class Person {
String introduce() {
return 이름: + name + , 나이: + age + 세;
}
}
public class Killer extends Person {
String introduce() {
return "무기 : + weapon + , + introduce();
}
} Recursive Call
Code Reuse
335. public class Person {
String introduce() {
return 이름: + name + , 나이: + age + 세;
}
}
public class Killer extends Person {
String introduce() {
return "무기 : + weapon + , + super.introduce();
}
}
super