JAVA/예제

[JAVA] ch05-14. Static method (스태틱 메서드) 2

밍글링글링 2017. 8. 22.
728x90
 
public class Ex14 {
    int iv = 10; // iv(instance variable) 
    static int cv = 20; //cv(class variable) 
    
    int iv2 = cv;
    //static int cv2 = iv; //(X)
    static int cv2 = new Ex14().iv; //(O)
    
    static void sm1(){ // sm(static method)
        System.out.println(cv);
        //System.out.println(iv);//(X)
        System.out.println(new Ex14().iv);//(O)
    }
    
    void im1(){ //im(instance method)
        System.out.println(cv);
        System.out.println(iv);
    }
    
    static void sm2(){ // sm(static method)
        sm1(); // = Ex14.sm1(); 
        //im1();
        new Ex14().im1();
    }
    
    void im2(){ 
        sm1(); // = this.sm1();
        im1();
    }
}

728x90

댓글