클래스는 상태(변수), 과 행위(메서드)를 가지고 있다.
객체에서 new 클래스명을 하면 클래스명 내의 모든 것들을 heap에 올린다.
객체에서 찾을 시 참조변수를 선언하여 찾는다.
클래스 코드
package ex04;
public class Circle {
public int radius;
public String color;
public double getArea() {
return 3.14 * radius * radius;
}
}
객체 코드
package ex04;
public class CircleTest {
public static void main(String[] args) {
Circle obj = new Circle();
obj.radius = 100;
obj.color = "blue";
double area = obj.getArea();
System.out.println("원의 면적은 : " + area);
}
}

Circle클래스를 CircleTest로 불러와 Circle안에 있는 getArea를 CircleTest에서도 사용 가능하다.
new = heap에 생성
오브젝트, 클래스, 인스턴스 그림 설명

오브젝트(object)는 메모리에 올라왔든, 안 올라 왔든, 상태와 행위가 있으면 오브젝트이다.
클래스는 인스턴스를 만들 수 있는 객체이다.
인스턴스는 메모리에 올라가 있는 객체이다.
Share article