The following 10 questions are similar to what you might see on the AP CSA exam for Unit 1 on Objects. You may only take this practice test once while logged in. There are no time limits, but it will keep track of how much time you take. Click on the finish button after you have answered all the questions, and the number correct and feedback on the answers will be displayed.
We estimate that a score of about 50% on this test would correspond to the passing grade of 3 on the AP exam, a score of 65% to a 4, and a score of 80% and above to a 5 on the AP exam. These are just estimates and may not correspond to individual scores.
public class Party
{
private int numInvited;
private boolean partyCancelled;
public Party()
{
numInvited = 1;
partyCancelled = false;
}
public Party(int invites)
{
numInvited = invites;
partyCancelled = false;
}
}
I. Party myParty;
II. int classSize = 20;
Party ourParty = new Party(classSize);
III. int numOfFriends = 6;
Party yourParty = new Party(numOfFriends + 3.0);
Consider the following class. Which of the following code segments, when placed in a method in a class other than Liquid, will construct a Liquid object l with a boilingPoint of 98.6 ?
Consider the following class. Assume that the Liquid object liquid has been properly declared and initialized in a method in a class other than Liquid. Which of the following statements are valid?
public class Dog
{
public void bark()
{
System.out.print("Woof ");
}
public void wag()
{
System.out.print("Wag Tail ");
}
public void happy()
{
wag();
bark();
}
/* Constructors not shown */
}
Which of the following code segments, if located in a method in a class other than Dog, will cause the message βWag Tail Wag Tail Woof β to be printed?
public void calculatePizzaOrder(int numOfPeople, int slicesPerPerson)
{
int numOfPizzas = (numOfPeople * slicesPerPerson)/8;
/* INSERT CODE HERE */
}
public void printOrder(int number)
{
System.out.println("Order " + number + " pizzas ");
}
What of the following lines would go into /* INSERT CODE HERE
*/ in line 4 in order to call the printOrder method to print the number of pizzas to order correctly?
Correct! If you had 8 people who want to eat 2 pizza slices each, numOfPizzas would be 8*2/8 = 2 pizzas, and printOrder would print out βOrder 2 pizzasβ.