일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 안드로이드 개발 2.0
- 안드로이드 개발 강좌
- sky 시리우스폰
- objective-c
- 안드로이드2.0
- 아이폰 배경화면
- MapView
- android
- 스카이 안드로이드폰 시리우스
- 하루한마디영어
- 안드로이드 배경화면
- 안드로이드 개발 2.0 강좌
- 영어
- 안드로이드 2.0 개발
- 인기있는 블로그 만들기
- 안드로이드폰
- 구글 안드로이드 개발
- 구글안드로이드
- 안드로이드2.0개발
- 스마트폰 배경화면
- 안드로이드 바탕화면
- 안드로이드개발
- 구글 안드로이드
- SKY 시리우스
- 안드로이드 개발
- 안드로이드
- Form Stuff
- 아이폰 바탕화면
- 스카이 안드로이드폰 시리우스 K양 동영상
- 하루 한마디 영어
- Today
- Total
moozi
상속연습 본문
class Person{
private String name;
Person(String name){
this.name=name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void speak() {
System.out.println("말하기");
}
public void eat() {
System.out.println("먹기");
}
public void walk() {
System.out.println("걷기");
}
public void sleep() {
System.out.println("잠자기");
}
}
class Student extends Person{
Student(String name) {
super(name);
}
public void study() {
System.out.println("공부하기");
}
}
class StudentWorker extends Student{
StudentWorker(String name) {
super(name);
}
public void work() {
System.out.println("일하기");
}
}
public class ExtendSample {
static void print(Person p) {
if(p instanceof Person) {
System.out.print("Person ");
}
if(p instanceof Student) {
System.out.print("Student ");
}
if(p instanceof StudentWorker) {
System.out.print("StudentWorker ");
}
System.out.println();
}
public static void main(String[] args) {
//Person 인스턴스 생성
Person hkd=new Person("홍길동");
hkd.sleep();
hkd.setName("홍길돈");
System.out.println(hkd.getName());
//Student 인스턴스 생성
Student lss=new Student("이순신");
System.out.println(lss.getName());
lss.study();
//StudentWorker 인스턴스 생성
StudentWorker sjdw=new StudentWorker("세종대왕");
System.out.println(sjdw.getName());
sjdw.work();
print(new Person("왕건"));
print(new Student("강감찬"));//upcasting.자동변환
print(new StudentWorker("이황"));//upcasting.자동변환
}
}