μ μ ( static ) λ©μλλ μΈμ€ν΄μ€ λ©μλμ λ€λ₯΄κ² ν΄λμ€λ‘λΆν° κ°μ²΄λ₯Ό μμ±νμ§ μκ³ μ§μ [ ν΄λμ€λͺ , λ©μλλͺ ] νμμΌλ‘ νΈμΆνλ λ©μλμ΄λ€.
μ΄ λ©μλλ λ©μλ μμ static μ΄λΌλ ν€μλλ₯Ό μ μ΄ μ£Όλ©°, λ©μλ λ΄λΆμμ ν΄λμ€μ μΈμ€ν΄μ€ κ°μ²΄ λ©€λ²λ₯Ό μ°Έμ‘°ν΄μ μλλ€. β
μ΄ static λ©μλλ μΈμ€ν΄μ€ κ°μ²΄λ‘λΆν° νΈμΆλ μ μμΌλ©°, λ°λμ ν΄λμ€ λͺ κ³Ό μ¬μ©λλ€.
κ°λ¨ν μμ λ‘ μ΄ν΄λ³΄κ² λ€.
public class Myclass
{
//μΈμ€ν΄μ€ λ©μλ
public int InstRun( )
{
return val;
}
// μ μ λ©μλ
public static int Run( )
{
return 1;
}
}
public class Client
{
public void Test( )
{
//μΈμ€ν΄μ€ λ©μλ μΆλ ₯
Myclass myclass = new myClass( );
int i = myclass.InstRun( );
int j = Myclass.Run( );
static μμ± λ° νλλ μμ static λ©μλμ κ°μ΄ { ν΄λμ€λͺ , μμ±λͺ }κ³Ό κ°μ΄ μ¬μ©νλ©°, λ€μ μμ κ°μ΄ staticμ μμ λΆμ¬ μ μνλ€.
ν΄λμ€ λ΄μ Non-static νλλ€μ ν΄λμ€ μΈμ€ν΄μ€λ₯Ό μμ±ν λλ§λ€ λ©λͺ¨λ¦¬μ λ§€λ² μλ‘ μμ±λκ² νλ λ°λ©΄,
- protected static int _id;
//static νλ- public static string Name { get ; set ; }
//static μμ±
λ π