Java - 생성자로 객체 정의해보기

parkkhee·2023년 2월 24일
0

3_LIKELION

목록 보기
5/14
package test;

import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {

        int 엄지손가락_길이 = new 사람().a왼팔.a손.a엄지손가락.길이;

        System.out.println(엄지손가락_길이 + "cm");
        // 출력 : 5cm

    }

}

class 사람{
    팔 a왼팔;
    사람(){
        a왼팔 = new();
    }
}
class{
    손 a손;(){
        a손 = new();
    }
}
class{
    엄지손가락 a엄지손가락;(){
        a엄지손가락 = new 엄지손가락();
    }
}
class 엄지손가락{
    int 길이;
    엄지손가락(){
        길이 = 5;
    }
}
profile
순우리말 백엔드 개발자

0개의 댓글