티스토리 뷰

JAVA

변수 유효 범위 체크하기

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

1. Card 클래스의 static 변수 width를 출력하세요.

2. Card 인스턴스의 멤버 변수 number를 출력하세요.

class Card {
	static int width = 10;
    int number = 8;
    int drawCardNumber() {
    	int pnumber;
        pnumber = getRandomInt(1, 13);
        return pnumber;
    }
    private static int getRandemInt(int min, int max) {
    	int randInt = (int)(Math.random() * max) + min;
        return randInt;
    }
}

public class Main {
	public static void main(String args[]) {
    	Card c = new Card();
        System.out.println(Card.width);
        System.out.println(c.number);
    }
}

'JAVA' 카테고리의 다른 글

캡슐화 활용해보기(2)  (0) 2023.09.19
캡슐화 활용해보기(1)  (0) 2023.09.19
static 메소드  (0) 2023.09.19
static 변수  (0) 2023.09.19
생성자 오버로드  (0) 2023.09.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함