package ch03;
public class Person {
String name;
int age;
int height;
int weight;
public void showInfo() {
System.out.println("name: " + name);
System.out.println("age: " + age);
System.out.println("height: " + height);
System.out.println("weight: " + weight);
}
}
package ch03;
public class Student extends Person{
public Student() {
super.name = "홍길동";
super.age = 21;
super.height= 175;
super.weight = 65;
}
}//밑에있는 Student와 Teacher를 먼저 만들고난뒤에 공통적인 부분을 뽑아
//부모를 만들어낸다.(상향식)
package ch03;
public class Teacher extends Person {
public Teacher() {
name = "홍선생";
age = 37;
height = 180;
weight = 70;
}
}
'Java > Excercise' 카테고리의 다른 글
inheritance ch04 FruitTest (0) | 2021.08.27 |
---|---|
inheritance ch04 Fruit (0) | 2021.08.27 |
inheritance ch02 Hero (0) | 2021.08.27 |
inheritance ch01 상속 02 (0) | 2021.08.27 |
inheritance ch01 상속 01 (0) | 2021.08.27 |