Java(Class2)_Inheritance_03

2024. 10. 30. 17:18·Java/기초 내용 정리

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
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(Class2)_Inheritance_05
  • Java(Class2)_Inheritance_04
  • Java(Class2)_Inheritance_02
  • Java(Class2)_Inheritance_01
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Java(Class2)_Inheritance_03
상단으로

티스토리툴바