Preview

02 - AP Exam question set #2 (Easy)

 1. The output of the following code is 0.
System.out.println(2 % 3);

  TRUE

  FALSE

 2. The output of the following code is 0.
System.out.println(1 / 3);

  FALSE

  TRUE

 3. Read the following excerpt and select the correct answer.
A student has created a Dinosaur class. 

The class contains variables to represent the following.

A String variable color to represent the color 
of the dinosaur

A String variable called breed to represent the 
species of the dinosaur

An int variable called age to represent the
age of the dinosaur

The object myDinosaur will be declared as type Dinosaur. 

Which of the following descriptions is accurate?

  age is an attribute of the myDinosaur object.

  Dinosaur is an instance of the myDinosaur class

  color, breed, and age are instances of the Dinosaur class

  An attribute of breed is String.

 4. The value of grade when the following code executes and score is 80, will be 'D'.
if (score >= 90) grade = "A";
if (score >= 80) grade = "B";
if (score >= 70) grade = "C";
if (score >= 60) grade = "D";
else grade = "E";

  FALSE

  TRUE

 5. Read the following excerpt and select the correct answer.
A student has created a Book class. 
The class contains variables to represent the following.

A String variable called title to represent 
the title of the book.

A String variable called author to represent 
the author of the book.

A double variable called price to represent the
price of the book.

The object cslewisBook will be declared as type 
Book

Which of the following descriptions is accurate?

  Title, director, and rating are instances of the cslewisBook object.

  cslewisBook is an instance of the Book class.

  Title, author, and price are instances of the cslewisBook object.

  Book is an instance of cslewisBook

 6. If x, in the following code, has been set to 250, what is printed?
if (x < 0)
{
   System.out.println("x is negative");
}
else if (x == 0)
{
    System.out.println("x is zero");
}
else
{
    System.out.println("x is positive");
}

  x is zero

  none of these is correct as the code has been set up incorrectly

  x is positive

  x is negative

 7. True or false: 'case 1' will print if x is less than 3 or y is greater than 2.
if (!(x < 3 || y > 2))
   System.out.println("case 1");
else
   System.out.println("case 2");

  FALSE

  TRUE

 8. What does the following code print?
for (int i = 3; i <= 12; i++)
{
   System.out.print(i + " ");
}

  3 4 5 6 7 8 9 10 11 12

  5 6 7 8 9

  3 5 7 9 11

  4 5 6 7 8 9 10 11 12

 9. How many times does the following method print a *?
for (int i = 3; i < 9; i++)
{
   System.out.print("*");
}

  7

  9

  6

  8

 10. Given the below, Which of the following statements will create an Event object that represents an event that has three people at it?
public class Event
{
    private int numOfPeople;
    private String eventHost;

    public Event (String name, int people)
    {
        eventHost = name;
        numOfPeople = people;
    }
}

  Event e = new Event (?John?, ?3?);

  Event e = new Event (?Mark?, ?three?);

  Event e = new Event (?Matthew?, three);

  Event e = new Event (?Luke?, 3);

 11. Which index is the last element in an array called nums at?

  None of these answers is correct

  nums.length - 1

  nums.length

  length.nums

 12. Which of the following declarations will cause a compile time error?

  String[] nameArray = {5, 3, 2};

  int[] scores = new int[5];

  int[] scoreArray = {50,90,85};

  int[] scores = null;

 13. It is sometimes necessary to decide whether to use an ArrayList or an array. Is the following statement true or false?
Every time an ArrayList fills up a new array is created that is twice as big. This can lead to extra space that is wasted

  FALSE

  TRUE

 14. How many columns does a have if it is created as follows
int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};

  8

  4

  2

  6

 15. Which one of the following has the following main function or purpose: A _____________initializes the fields in the object.

  class's instance variable

  class's attribute

  class's constructor

  class's object

 16. Overloading occurs when two methods perform the same essential operation, but take _____________.

  a different number and/or type of parameters.

  exactly the same number and type of parameters.

  different starting values (initialized values)

  the form of different objects.

 17. Which line has the recursive call?
public static int factorial(int n)
{
   if (n == 0)
      return 1;
   else return n * factorial(n-1);
}

  4

  5

  3

  1

 18. Which line has the recursive call?
public static int mystery(int n)
{
   if (n == 0)
      return 1;
   else return n * static(n-1);
}

  3

  There is no recursive call

  5

  1

 19. Which of these will occur if the recursive method does not have a base case?

  The program will fail to run at all

  An infinite loop occurs

  The system will stop the program after a single call

  A compile time error will be generated