클래스 상속 I
작성자 정보
- 작성자 최고관리자
- 작성일
컨텐츠 정보
- 조회 304
본문
Main JAVA --------------------------------------------------------------------------------------
Person JAVA --------------------------------------------------------------------------------------
Student JAVA --------------------------------------------------------------------------------------
Teacher JAVA --------------------------------------------------------------------------------------
public class Main {
public static void main(String[] args) {
Student student = new Student("홍길동", 20, 175, 80, "20170101", 1, 4.5);
Teacher teacher = new Teacher("김딜동", 56, 180, 87, "ABC001",3000000,3);
student.show();
teacher.show();
}
}
Person JAVA --------------------------------------------------------------------------------------
public class Person {
private String name;
private int age;
private int height;
private int weight;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public Person(String name, int age, int height, int weight) {
super();
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
}
Student JAVA --------------------------------------------------------------------------------------
public class Student extends Person {
private String studentID;
private int grade;
private double GPA;
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public double getGPA() {
return GPA;
}
public void setGPA(double gPA) {
GPA = gPA;
}
public Student(String name, int age, int height, int weight, String studentID, int grade, double gPA) {
super(name, age, height, weight);
this.studentID = studentID;
this.grade = grade;
GPA = gPA;
}
public void show() {
System.out.println("-------------------------");
System.out.println("학생 이름 : "+getName());
System.out.println("학생 나이 : "+getAge());
System.out.println("학생 키 : "+getHeight());
System.out.println("학생 몸무게 : "+getWeight());
System.out.println("학생 아이디: "+getStudentID());
System.out.println("학생 학년: "+getGrade());
System.out.println("학생 학점: "+getGPA());
}
}
Teacher JAVA --------------------------------------------------------------------------------------
public class Teacher extends Person {
private String teacherID;
private int monthSalary;
private int workYear;
public String getTeacherID() {
return teacherID;
}
public void setTeachedID(String teacherID) {
this.teacherID = teacherID;
}
public int getMonthSalary() {
return monthSalary;
}
public void setMonthSalary(int monthSalary) {
this.monthSalary = monthSalary;
}
public int getWorkYear() {
return workYear;
}
public void setWorkYear(int workYear) {
this.workYear = workYear;
}
public Teacher(String name, int age, int height, int weight, String teacherID, int monthSalary, int workYear) {
super(name, age, height, weight);
this.teacherID = teacherID;
this.monthSalary = monthSalary;
this.workYear = workYear;
}
public void show() {
System.out.println("-------------------------");
System.out.println("교사 이름 : "+getName());
System.out.println("교사 나이 : "+getAge());
System.out.println("교사 키 : "+getHeight());
System.out.println("교사 몸무게 : "+getWeight());
System.out.println("교직원 번호 : "+getTeacherID());
System.out.println("교사 월급 : "+getMonthSalary());
System.out.println("교사 연차 : "+getWorkYear());
}
}
관련자료
-
이전
-
다음
댓글 0개
등록된 댓글이 없습니다.