20241-10-30




주민번호 >>> 001111-0000000
이 름 >>> 홍길자
나 이 >>> 27
직 업 >>> 대학생
학 과 >>> 영문학과
주민번호 >>> 002222-2222222
이 름 >>> 홍길동
나 이 >>> 50
직 업 >>> 회사원
급 여 >>> 5000 만원
package inheritance;
public class Person {
// 멤버변수
String juminNo; // 주민번호
String name; // 이름
String age; // 나이
String job; // 직업
}
package inheritance;
public class Student extends Person {
String major; // 학과
public Student() {
super();
} // 기본 생성자
public Student
(String juminNo, String name, String age, String job, String major) {
super();
this.juminNo = juminNo;
this.name = name;
this.age = age;
this.job = job;
this.major = major;
} // 인자 생성자
void getStudentInfo() {
System.out.println("주민번호 >>> " + juminNo);
System.out.println("이 름 >>> " + name);
System.out.println("나 이 >>> " + age);
System.out.println("직 업 >>> " + job);
System.out.println("학 과 >>> " + major);
} // getStudentInfo() 메서드 end
}
package inheritance;
public class Employee extends Person {
int salary; // 급여
void getEmployeeInfo() {
System.out.println("주민번호 >>> " + juminNo);
System.out.println("이 름 >>> " + name);
System.out.println("나 이 >>> " + age);
System.out.println("직 업 >>> " + job);
System.out.println("급 여 >>> " + salary + " 만원");
} // getEmployeeInfo() 에서드 end
}
package inheritance;
public class Person_03 {
public static void main(String[] args) {
// 기본 생성자가 없는 경우 error 발생.
//Student student = new Student();
Student student = new Student(
"001111-0000000", "홍길자", "27", "대학생", "영문학과");
student.getStudentInfo();
System.out.println();
Employee employee = new Employee();
employee.juminNo = "002222-2222222";
employee.name = "홍길동";
employee.age = "50";
employee.job = "회사원";
employee.salary = 5000;
employee.getEmployeeInfo();
}
}'Java > 기초 내용 정리' 카테고리의 다른 글
| Java(Class2)_Inheritance_05 (0) | 2024.10.30 |
|---|---|
| Java(Class2)_Inheritance_04 (0) | 2024.10.30 |
| Java(Class2)_Inheritance_02 (0) | 2024.10.30 |
| Java(Class2)_Inheritance_01 (0) | 2024.10.30 |
| Java(Class&Method)_Exam_06 (0) | 2024.10.29 |