λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Java

[Java] 클래슀 κΈ°λŠ₯을 κ΅¬ν˜„ν•˜λŠ” λ©”μ„œλ“œ

by μ½”λ”©ν•˜λŠ” λΆ•μ–΄ 2021. 2. 17.
λ°˜μ‘ν˜•

μ˜€λŠ˜μ€ 운영체제, λ°μ΄ν„°λ² μ΄μŠ€, λ„€νŠΈμ›Œν¬, κ°œλ°œν™˜κ²½μ— λŒ€ν•œ κ°„λ‹¨ν•œ 이둠을 λ°°μ›Œμ„œ Java μˆ˜μ—…μ€ 1μ‹œκ°„λ°–μ— μ•ˆν–ˆλ‹€.

​

​

​

*클래슀 κΈ°λŠ₯을 κ΅¬ν˜„ν•˜λŠ” λ©”μ„œλ“œ

package classpart;

public class Student {

	int studentID;
	String studentName;
	int grade;
	String address;

	public void showStudentInfo() {
		System.out.println(studentName + "," + address);  // 이름, μ£Όμ†Œ
	}

	public String getStudentName() {  // ν•™μƒμ˜ 이름을 λ°˜ν™˜ν•˜λŠ” getter λ©”μ„œλ“œ
		return studentName;
	}

	public void setStudentName(String studentName) {  // 학생 이름을 λ§€κ°œλ³€μˆ˜λ‘œ 전달
		this.studentName = studentName;
	}

    public int getStudentID() {
		return studentID;
	}

	public void setStudentID(int studentID) {
		this.studentID = studentID;
	}

    public int getGrade() {
		return grade;
	}

	public void setGrade(int grade) {
		this.grade = grade;
	}

    public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

}

-get + μ‹œμž‘λ©€λ²„λ³€μˆ˜μ— 이름을 λΆ™μΌλ•Œ 첫 κΈ€μžλŠ” λŒ€λ¬Έμžλ‘œ!

λ°˜μ‘ν˜•

λŒ“κΈ€