Java Reference
In-Depth Information
Review Questions
1.
A class is a description of a(n) _______________.
2.
An object is an instance of a(n) _______________.
3.
When designing a class to describe an object, how are the attributes of the object rep-
resented in the class?
4.
When designing a class to describe an object, how are the behaviors of the object rep-
resented in the class? Use the following BaseballGame and Team classes to answer the
ensuing questions.
public class Team
{
public String name;
public String city;
public int numberOfWins, numberOfLosses;
}
public class BaseballGame
{
public Team home, visitor;
public int homeScore, visitorScore;
public void homeTeamScored(int numberOfRuns)
{
homeScore += numberOfRuns;
}
public void visitorTeamScored(int numberOfRuns)
{
visitorScore += numberOfRuns;
}
public void gameOver()
{
if(homeScore > visitorScore)
{
home.numberOfWins++;
visitor.numberOfLosses++;
}
else
{
visitor.numberOfWins++;
home.numberOfLosses++;
}
Search WWH ::




Custom Search