티스토리 뷰

JAVA

static 메소드

코린이도이 2023. 9. 19. 10:25

1. 매개변수가 없고 카드의 넓이의 값을 int형으로 반환하는 메소드 getArea()를 작성하세요.

class Card {
	static int width = 10;
    static int height = 16;
    
    String shape;
    int number;
    
    Card(String shape, int number) {
    	this.shape = shape;
        this.number = number;
    }
    static int getArea() {
    	return width * height;
    }
}

public class Main {
	public static void main(String args[]) {
    	System.out.println("카드의 넓이 : " + Card.getArea());
    }
}

'JAVA' 카테고리의 다른 글

캡슐화 활용해보기(1)  (0) 2023.09.19
변수 유효 범위 체크하기  (0) 2023.09.19
static 변수  (0) 2023.09.19
생성자 오버로드  (0) 2023.09.19
생성자 구현하기  (0) 2023.09.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함