๐Ÿผ[JAVA]์˜ค๋ฒ„๋ผ์ด๋”ฉ๐Ÿผ

์˜ค๋ฒ„๋กœ๋”ฉ๊ณผ ์˜ค๋ฒ„๋ผ์ด๋”ฉ

๊ฐ์ฒด ์ง€ํ–ฅ์˜ ํŠน์ง•์€ ๋‹คํ˜•์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

์˜ค๋ฒ„๋กœ๋”ฉ


์กฐ๊ฑด

  • ๋™์ผํ•œ ํด๋ž˜์Šค ๋ฐ ์ƒ์† ๊ด€๊ณ„ ์‹œ ๋ฐœ์ƒํ•œ๋‹ค.
  • ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์ด ๋™์ผํ•ด์•ผ ํ•œ๋‹ค.
  • ๋งค๊ฐœ๋ณ€์ˆ˜ / ๋ฆฌํ„ดํƒ€์ž…์ด ์„œ๋กœ ๋‹ฌ๋ผ์•ผ ํ•œ๋‹ค.
  • ex) void test(){}
    void test(int name){}
    int test(){}

์˜ค๋ฒ„๋กœ๋”ฉ์€ ์ฃผ๋กœ ์ƒ์„ฑ์ž ์ƒ์„ฑ ์‹œ ๋งŽ์ด ์ผ์–ด๋‚œ๋‹ค.

class Student{
	String name;
    int age;
    public Student(){}
    public Student(String name){
    	this.name = name;
        }
    public Student(int age){
    	this.age = age;
        }
 public class Test{
 	public static void main(String args[]){
 
            //public Student(){} ํ˜ธ์ถœ
            Student s1 = new Student(); 
            //public Student(String name); ํ˜ธ์ถœ
            Studnet s2 = new Student("ํ™๊ธธ๋™");
            
         }
   }
           
            

์˜ค๋ฒ„๋ผ์ด๋”ฉ

์ƒ์œ„ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ์— ์•ฝ๊ฐ„ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๊ฐ™์€ ์ด๋ฆ„์œผ๋กœ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ •์˜ํ•˜๋Š” ๊ฒƒ

  • ์ƒ์œ„ ํด๋ž˜์Šค์— ์žˆ๋Š” ๋ฉ”์†Œ๋“œ์™€ ๋˜‘๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋ฅผ ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ๋‹ค์‹œ ์žฌ์ •์˜ํ•˜๋Š” ๊ฒƒ
  • ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ ๋ฉ”์†Œ๋“œ ๊ธฐ๋Šฅ์„ ๋ฐ”๊พธ๋Š” ๊ฒƒ

์˜ค๋ฒ„๋ผ์ด๋”ฉ ์กฐ๊ฑด
(1) ์ƒ์œ„ ํด๋ž˜์Šค ๋ฉ”์†Œ๋“œ ์ด๋ฆ„, ์ธ์ž,๋ฐ˜ํ™˜ํ˜• ์™„์ „ํžˆ ๋™์ผ
(2) static, final, private, ๋ฉ”์†Œ๋“œ์˜ ๊ฒฝ์šฐ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ๋ถˆ๊ฐ€


์˜ค๋ฒ„๋กœ๋”ฉ๊ณผ ์˜ค๋ฒ„๋ผ์ด๋”ฉ์˜ ์ฐจ์ด

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ