Java
[Java] ์ธ์คํด์ค ์ฌ๋ฌ ๊ฐ ์์ฑํ๊ธฐ
์ฝ๋ฉํ๋ ๋ถ์ด
2021. 2. 18. 04:09
๋ฐ์ํ
โถ ์ธ์คํด์ค ์ฌ๋ฌ ๊ฐ ์์ฑํ๊ธฐ
package classpart;
public class StudentTest1 {
public static void main(String[] args) {
Student student1 = new Student(); // ์ฒซ ๋ฒ์งธ ํ์ ์์ฑ
student1.studentName = "์์ฐ์";
System.out.println(student1.getStudentName());
Student student2 = new Student(); // ๋ ๋ฒ์งธ ํ์ ์์ฑ
student2.studentName = "์์น์ฐ";
System.out.println(student2.getStudentName());
}
}
-new Student( )๋ฅผ ์ ์ธํ๋ฉด Student ํ๋๊ฐ ์์ฑ๋๋๋ฐ ๊ฐ Student๋ studentID, studentName ๋ฑ์ ๋ฉค๋ฒ ๋ณ์๋ฅผ ๊ฐ์ง๊ณ ์๋ค. ๊ทธ ๋ ์ด๋ค ๋ณ์๋ฅผ ์ ์ฅํ ๋ ์ฌ์ฉํ๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋ฉ๋ชจ๋ฆฌ(heap memory)๋ผ๊ณ ํ๋ค.
๋ฐ์ํ