" ์ ์ ๋ฉ์๋ ์ธ์๋ ์ ์ ํด๋์ค๊ฐ ์์ต๋๋ค. ๋์ค์ ์ด์ ๋ํด ์์ธํ ์ค๋ช ํ๊ฒ ์ต๋๋ค. ์ง๊ธ์ ์๋ฅผ ๋ณด์ฌ ๋๋ฆฌ๊ฒ ์ต๋๋ค."
public class StaticClassExample
{
private static int catCount = 0;
public static void main(String[] args) throws Exception
{
Cat bella = new Cat("Bella");
Cat tiger = new Cat("Tiger");
System.out.println("Cat count " + catCount);
}
public static class Cat
{
private String name;
public Cat(String name)
{
this.name = name;
StaticClassExample.catCount++;
}
}
}
" Cat ๊ฐ์ฒด๋ฅผ ์ํ๋ ๋งํผ ๋ง๋ค ์ ์์ต๋๋ค. ํ์ง๋ง ์ ์ ๋ณ์์ ๊ฒฝ์ฐ์๋ ๊ทธ๋ ์ง ์์ต๋๋ค. ์ ์ ๋ณ์์ ๋ณต์ฌ๋ณธ์ ํ๋๋ง ์กด์ฌํฉ๋๋ค."
"ํด๋์ค ์ ์ธ์์ ์ ์ ์์ ์๋ฅผ ์ฌ์ฉํ๋ ์ฃผ์ ๋ชฉ์ ์ Cat ๊ณผ StaticClassExample ํด๋์ค ์ฌ์ด์ ๊ด๊ณ๋ฅผ ์ ์ดํ๋ โโ๊ฒ์ ๋๋ค . ์์ด๋์ด๋ ๋๋ต ์ด๋ ์ต๋๋ค. Cat ํด๋์ค๋ StaticClassExample ๊ฐ์ฒด์ ์ฐ๊ฒฐ๋์ด ์์ง ์์ผ๋ฉฐ ์ธ์คํด์ค์ ์ก์ธ์คํ ์ ์์ต๋๋ค(๋น- static) StaticClassExample ํด๋์ค์ ๋ณ์์ ๋๋ค."
"๊ทธ๋ฌ๋ฉด ์์ ์์ ์์ ์ ๋ง๋ค ์ ์์ต๋๊น?"
"์. Java๋ ํ์ฉํ์ง๋ง ์ง๊ธ์ ๋๋ฌด ๋ง์ด ์๊ฐํ์ง ๋ง์ญ์์ค. ๋์ค์ ๋ช ๊ฐ์ง ์ฌํญ์ ๋ ์ค๋ช ํ๋ฉด ๋ ๋ช ํํด์ง ๊ฒ์ ๋๋ค."
"๊ทธ๋ฌ์ผ๋ฉด ์ข๊ฒ ์ด, ๋ฆฌ์."
GO TO FULL VERSION