| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
medium Solved by 5 students
Java Static Variables and Methods
< Prev
Next >

Consider the following class definition.

public class GameSession {
    private static int sessionCount = 0;
    private static int totalPlayers = 0;
    private int sessionID;
    private int players;
    
    public GameSession(int numPlayers) {
        sessionCount++;
        sessionID = sessionCount;
        players = numPlayers;
        totalPlayers += numPlayers;
    }
    
    public static void resetStats() {
        sessionCount = 0;
        totalPlayers = 0;
    }
    
    public int getSessionID() {
        return sessionID;
    }
    
    public static int getTotalPlayers() {
        return totalPlayers;
    }
}

What is printed as a result of executing the following code segment?

GameSession game1 = new GameSession(4);
GameSession game2 = new GameSession(2);
System.out.println(game1.getSessionID() + " " + GameSession.getTotalPlayers());
GameSession.resetStats();
GameSession game3 = new GameSession(3);
System.out.println(game2.getSessionID() + " " + GameSession.getTotalPlayers());
A

1 4
2 3

B

1 6
0 3

C

4 6
2 3

D

1 6
2 3

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2y.seong202711 2m 13s -33
#3tellabhinaya01 1m 43s -113
#4bommasam00027 2h 13m -7,880
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy