★객체 a = 객체 b할 경우 b의 값도 바뀜

김희주·2023년 5월 21일
0

자잘한 Tip

목록 보기
6/8
post-thumbnail
public class Main {

    public static void main(String[] args) {
        Distance a = new Distance();
        a.setDistance(3);
        System.out.println("a의 값 : " + a.getDistance());

        Distance b = new Distance();
        b.setDistance(5);
        System.out.println("b의 값 : " + b.getDistance());

        Distance c = b;
        c.setDistance(7);
        System.out.println("c의 값 : " + c.getDistance());
        System.out.println("b의 값 : " + b.getDistance());
    }
}
a의 값 : 3
b의 값 : 5
c의 값 : 7
b의 값 : 7
profile
백엔드 개발자입니다 ☘

0개의 댓글