GitHub

https://github.com/Backcoder-June

BackCoder 기록 그리고 숙달

Back to the Java

Back to the Java - Static

Backcoder 2022. 5. 27. 16:48
static  -> method / variables
     class cal {

     int a; int b;
     static int c;

 <평범한 instance 메소드 일때>                 => 다 접근 가능.  대신, instance 로(c1.) 꺼내써야함
     void sum(){ a + b }       (o)  가장 평범
     void sum(){ c }           (o)

    c1.sum(a + b + c)        (o)

 <c1 안만들고 직접 하려고 static 메소드 쓸때>    => Static 은 끼리끼리만 논다. 대신 직접 꺼낼수 있다.
     static void sum(){ a + b }  (x)      int a, b (x)
     static void sum(){ c }      (o)  static int c (o)

     calcul.(static)sum ( c )   (o)
     calcul.(static)sum ( a )   (x)

     c1.(static)sum (x)