[상속-5] Constructor -2

seratpfk·2022년 8월 1일
0

JAVA

목록 보기
56/96

Person클래스 생성(메인메소드 없음)

	private String name;
	public Person(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

Student클래스 생성(메인메소드 없음)

public class Student extends Person {
	private String school;
	public Student(String name, String school) {
		super(name);
		this.school = school;
	}
	public String getSchool() {
		return school;
	}
	public void setSchool(String school) {
		this.school = school;
	}
}

StudentMain클래스 생성(메인메소드 생성)

Student student = new Student("tom", "goodee");
System.out.println(student.getName());
System.out.println(student.getSchool());

출력:
tom
goodee

0개의 댓글