[상속-6] Constructor 연습문제

seratpfk·2022년 8월 1일
0

JAVA

목록 보기
57/96

연습문제

  • 학교 다니면서 도서관에서 아르바이트 하는 학생이 있다.
  • 클래스: Alba
  • 필드: String company;
  • 생성자 호출: new Alba("jessica(getName)", "seoul univ(getSchool)", "library(getCompany)");

Alba클래스 (메인메소드 없음)

public class Alba extends Student {	
	private String company;
	public Alba(String name, String school, String company) {
		super(name, school);
		this.company = company;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
}

AlbaMain클래스 (메인메소드 설정)

		Alba alba = new Alba("jessica", "seoul univ", "library");
		System.out.println(alba.getName());
		System.out.println(alba.getSchool());
		System.out.println(alba.getCompany());

출력:
jessica
seoul univ
library

  • 생성자 만들기: 이클립스 -> source -> Generate Constructor Using Fied...

0개의 댓글