๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java] ํด๋ž˜์Šค์— main( ) ํ•จ์ˆ˜ ํฌํ•จํ•˜๊ธฐ

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 18.
๋ฐ˜์‘ํ˜•

โ–ถ ํด๋ž˜์Šค์— main( ) ํ•จ์ˆ˜ ํฌํ•จํ•˜๊ธฐ

package classpart;

public class Student {

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

	public String getStudentName() {
		return studentName;
	}

	public static void main(String[] args) {  // main() ํ•จ์ˆ˜
		Student studentAhn = new Student();
		studentAhn.studentName = "์•ˆ์—ฐ์ˆ˜";

		System.out.println(studentAhn.studentName);
		System.out.println(studentAhn.getStudentName());
	}
}

 

Student studentAhn = new Student();

Student ํด๋ž˜์Šค ์ž๋ฃŒํ˜•์œผ๋กœ studentAhn ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ 

new Student( );๋กœ Student ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ studentAhn์— ๋Œ€์ž…ํ•œ๋‹ค๋Š” ๋œป.

์ด๋•Œ, studentAhn์„ ์ฐธ์กฐ๋ณ€์ˆ˜๋ผ๊ณ  ํ•˜๊ณ , ์ด ๋ณ€์ˆ˜๊ฐ€ ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€