[Java] 자바 클래스 private 접근제어자와 getter/setter 예제
//자바 클래스의 private 접근제어자와 getter/setter 예제 public class Pg62 { public static void main(String[] args) { Rectangle2 r1 = new Rectangle2(5,3,10,20); r1.print(); r1.draw(); Rectangle2 r2 = new Rectangle2(8,9,10,20); r2.print(); r2.draw(); System.out.println("r2의 넓이는 :" +r2.area()); } } class Shape2{ private int x; private int y; public Shape2(int x,int y) { this.x = x; this.y = y; } public void print() { System.out.printf("x좌표 : %d, y좌표: %d\n",this.x,this.y); } public int getX() { return this.x; } public int getY() { return this.y; } } class Rectangle2 extends Shape2{ private int width; private int height; Rectangle2(int x, int y, int width, int height){ super(x,y); this.width=width; this.height = height; } public double area() { return width * height; } public void draw() { System.out.printf("(%d, %d) 위치에 가로: %d 세로: %d\n",super.getX(),super.getY(),this.width, this.heig...