개인 공부 (23.07~

[JAVA] 클래스, 객체, 인스턴스 용어 정리

Song쏭 2023. 7. 24. 17:39

The basic concept of OOP is this: Class >> Object >> Instance.

 

instance means allocating the memory space by the jvm and 

object means initializing the variables inside that instance. 

But most the people says like instance is object and object is instance.


In simple words, 

Instance refers to the copy of the object at a particular time 

whereas object refers to the memory address of the class.

 

객체를 생성하는 데 클래스가 사용된다.

객체를 생성해서 메모리에 딱 올라간! 내가 만든 그 객체의 실체 자체를 인스턴스라고 한다.

 

클래스 Class : the blue print.

객체를 만들 수 있는 설명서.

완성하면 이렇게 동작할거야. 라는 설명 전부가 적혀있는 것.

 

객체 Object : an instance of a Java class, meaning it is a copy of a specific class.

an actual thing that is built based on the ‘blue print’.

Objects are the definitions of something

이 세상에 존재하는 모든 것. 우리가 프로그래밍 세상에서 표현하고 싶은 현실 개념.

프로그램이 실행되면서 생성되고 파괴되며,

동일한 클래스를 사용하여 생성된 경우 

구조가 동일한 객체가 많을 수 있다.

 

인스턴스 Instance : a specific realization of any object. 

 An instance is a virtual copy (but not a real copy) of the object.

instances are the physical things.

메모리에 올라간 객체의 실체.

프로그래밍을 통해서 실제로 만들어진 것 자체! 

내가 컴퓨터 객체 생성을 통해서 실제 나의 맥북을 만든 것이다. 그럼 나의 맥북 자체를 인스턴스라고 부르는 것이다.

클래스를 사용하여 생성된 객체는 해당 클래스의 인스턴스라고 한다.

 

- 인스턴스 변수 : 객체가 포함하는 변수. 아래의 car클래스를 통해서 Car 객체를 생성하고, color필드만 객체 생성하여 사용했다면, 인스턴스 변수는 color만 해당된다. 만약 객체 생성해서 color, num필드 둘다 사용했다면 인스턴스 변수는 두개 모두일 것이다.

 

- 인스턴스 메서드 : 객체가 포함하는 메서드. 메서드도 변수와 마찬가지로 객체생성 후 사용되는 메서드만 인스턴스 메서드라고 불린다.

public class Car {

    private String color;
    private int num;

    void ride(String color) {
        System.out.println(color + "차가 달린다.");
    }

    void stop(String num) {
        System.out.println(num + "차가 멈춘다.");
    }
}

 

나중에 또 헷갈릴 때 다시 보려고 북마크용으로 기록중입니다:)