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