2015. 1. 13. 22:31
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

캡슐화란 : 어떠한 정보를 특정 클래스 private 멤버변수에 메소드를 사용하여 담아두고 저장하는 것

  -> 사용할 때는 public 메소드로 접근하여 정보를 수정하거나 불러내서 사용한다



-------------------------


package dataStructure;

public class encapsulating {
   
        private int x;
        private int y;
 
        // 객체 생성시 x,y를 입력받는 형태의 생성자 정의
        public encapsulating(int x, int y) {
            this.x = x;
            this.y = y;
        }

        // x값을 입력받아 멤버변수 x에 담아 두기
        public void setX(int x) {
            this.x = x;
        }

        // y의 값을 입력받아 멤버변수y에 담아 두기
        public void setY(int y) {
            this.y = y;
        }

        // 증가시킬 x,y값을 입력받아 멤버변수에 x,y값을 증가시켜 담아두기
        public void moveXY(int x, int y) {
            this.x += x;
            this.y += y;
        }

        public int getX() {
            return this.x;
        }

        public int getY() {
            return this.y;
        }
    }

-===============



package dataStructure;


public class enMain {

    public static void main(String[] args) {
        encapsulating point = new encapsulating(100, 100);
        point.setX(200);
        point.setY(300);
        point.moveXY(50, 50);
       
        System.out.println(point.getX()+" "+point.getY());
    }

}




'Java' 카테고리의 다른 글

an usage of Vector  (0) 2015.01.14
basic Vector  (0) 2015.01.14
building a Stack structure  (0) 2015.01.13
ProcessBuilder  (0) 2015.01.12
UrlFrame, getting the page source and save as a txt file  (0) 2015.01.06
Posted by af334