wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP CSA Unit 2 Practise MCQ

Total questions: 21

Worksheet time: 18mins

Name
Class
Date
1.

A student has created a Cat class. The class contains variables to represent the following.

  • A String variable called color to represent the color of the cat

  • A String variable called breed to represent the breed of the cat

  • An int variable called age to represent the age of the cat

The object myCat will be declared as type Cat. Which of the following descriptions is accurate?

a)

An attribute of breed is String.

b)

color, breed, and age are instances of the Cat class.

c)

Cat is an instance of the myCat class.

d)

age is an attribute of the myCat object.

e)

An attribute of Cat is myCat.
Check MeCompare me

2.

A student has created a Movie class. The class contains variables to represent the following.

  • A String variable called title to represent the title of the movie

  • A String variable called director to represent the director of the movie

  • A double variable called rating to represent the rating of the movie

The object scaryMovie will be declared as type Movie. Which of the following descriptions is accurate?

a)

An attribute of the scaryMovie class is title.

b)

scaryMovie is an instance of the Movie class.

c)

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

d)

An attribute of the Movie instance is scaryMovie

e)

Movie is an instance of scaryMovie.
Check MeCompare me

3.

Which of the following code segments will correctly create an instance of a Person object?

a)

new Person john = Person("John", 16);

b)

Person john("John", 16);

c)

Person john = ("John", 16);

d)

Person john = new Person("John", 16);

e)

Person john = new Person(16, "John");

4.

What is the value of len after the following executes?

a)

2

b)

10

c)

11

d)

8

5.

What is the value of pos after the following code executes?

a)

-1

b)

3

c)

5

d)

4

6.

What is the value of s1 after the following code executes?

a)

Hey

b)

he

c)

H

d)

h

7.

Consider the following class. Which of the following code segments would successfully create a new Movie object?

a)

Movie four = new Movie("My Cool Movie", "Steven Spielburg", "4.4");

b)

Movie one = new Movie("Harry Potter", "Bob");

c)

Movie two = new Movie("Sponge Bob");

d)

Movie three = new Movie(title, rating, director);

e)

Movie five = new Movie(t);

8.

Given the BankAccount class definition below, what is the output of the code in the main method?

a)

100.0

b)

110.0

c)

10.0

d)

90.0

9.

Given the following code segment, what is the value of num when it finishes executing? Math.random() returns a random decimal number between 0 and up to 1, for example 0.4.

a)

random number from 0 - 4

b)

random number from 1 - 5

c)

random number from 5 - 9

d)

random number from 5 - 10

10.

Given the following code segment, what is the value of num when it finishes executing? Math.random() returns a random decimal number between 0 and up to 1, for example 0.4.

a)

random number from -5 to 5

b)

random number from 0 to 5

c)

random number from 0 to 10

d)

random number from -5 to 4

11.

After the following code is executed, which of I,II, and/or III will evaluate to true?

a)

I,II,III

b)

I & III

c)

II only

d)

II & III

e)

III only

12.

What is output from the following code?

a)

eor

b)

erorg

c)

org

d)

orgi

e)

You will get am index out of bounds exception

13.

Given the following code segment, what is the value of s1 after the code executes?

a)

null

b)

hi there

c)

HI THERE

d)

hI tHERE

e)

Hi There

14.

There is a method called checkString that determines whether a string is the same forwards and backwards. The following data set inputs can be used for testing the method. What advantage does Data Set 2 have over Data Set 1?


a)

Data set 2 should return true and one that should return false

b)

The strings in Data Set 2 are all lowercase

c)

All strings in Data Set 2 have the same number of characters

d)

There are no advantages

e)

Data Set 2 contains fewer values than Data Set 1

15.

A car dealership needs a program to store information about the cars for sale.For each car, they want to keep track of the following information: the number of doors (2 or 4),its average number of miles per gallon, and whether the car has air conditioning. Which of the following is the best design?

a)

Use one class, Car, which has three attributes: int numDoors, double mpg, and boolean hasAir.

b)

Use four unrelated classes: Car, Doors, MilesPerGallon, and AirConditioning

c)

Use a class, Car, which has three subclasses: Doors, MilesPerGallon, and AirConditioning

d)

Use a class Car, which has a subclass Doors, with a subclass AC, with a subclass MPG.

e)

Use three classes: Doors, AirConditioning, and MilesPerGallon, each with a subclass Car.
Check MeCompare me

16.

Assume that SomeClass and MainClass are properly defined in separate files. What is the output of the code in main()?

a)

Hello Bob Hello

b)

Hello Bob

c)

Hello Hello Bob

d)

Hello Bob Hello Bob

17.

What is the output of the following code?

a)

Woo Hoo Hoo Woo

b)

Hoo Woo Woo

c)

Woo Woo Hoo Hoo

d)

Woo Hoo Woo Hoo

e)

Woo Hoo Hoo

18.

Given the following code segment, which of the following is true?

a)

II, III, and IV

b)

I, II, III, IV

c)

II and IV

d)

IV only
Check MeCompare me

e)

II only

19.

What does the following code print?

a)

1353

b)

21

c)

Run-time error

d)

138

e)

Compile-time error

20.

Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?

a)

unknown value

b)

Compile Error

c)

0

d)

Run-time Error

21.

Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?

a)

unknown value

b)

0

c)

compile error

d)

runtime error