클래스는 상태(변수)와 행위(메소드)를 가진다.
new를 통해 static이 붙지 않은 모든 것들을 heap에 올린다. (인스턴스가 된다.)
heap에 있는 값을 찾을 때는 참조 변수.이름으로 찾는다.
(여기서 .은 객체 연결 연산자이다.)
package ex04;
public class Circle {
public int radius;
public String color;
public double getArea() {
return 3.14 * radius * radius;
}
public static void main(String[] args) {
Circle obj;
obj = new Circle();
obj.radius = 100;
obj.color = "blue";
double area = obj.getArea();
System.out.println("원의 면적 : " + area);
}
}

Share article