NEW
Font size
WorksheetsAP CSA Unit 2 Practise MCQ
Total questions: 21
Worksheet time: 18mins
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?
An attribute of breed is String.
color, breed, and age are instances of the Cat class.
Cat is an instance of the myCat class.
age is an attribute of the myCat object.
An attribute of Cat is myCat.
Check MeCompare me
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?
An attribute of the scaryMovie class is title.
scaryMovie is an instance of the Movie class.
Title, director, and rating are instances of the scaryMovie object.
An attribute of the Movie instance is scaryMovie
Movie is an instance of scaryMovie.
Check MeCompare me
Which of the following code segments will correctly create an instance of a Person object?
new Person john = Person("John", 16);
Person john("John", 16);
Person john = ("John", 16);
Person john = new Person("John", 16);
Person john = new Person(16, "John");
What is the value of len after the following executes?
2
10
11
8
What is the value of pos after the following code executes?
-1
3
5
4
What is the value of s1 after the following code executes?
Hey
he
H
h
Consider the following class. Which of the following code segments would successfully create a new Movie object?
Movie four = new Movie("My Cool Movie", "Steven Spielburg", "4.4");
Movie one = new Movie("Harry Potter", "Bob");
Movie two = new Movie("Sponge Bob");
Movie three = new Movie(title, rating, director);
Movie five = new Movie(t);
Given the BankAccount class definition below, what is the output of the code in the main method?
100.0
110.0
10.0
90.0
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.
random number from 0 - 4
random number from 1 - 5
random number from 5 - 9
random number from 5 - 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.
random number from -5 to 5
random number from 0 to 5
random number from 0 to 10
random number from -5 to 4
After the following code is executed, which of I,II, and/or III will evaluate to true?
I,II,III
I & III
II only
II & III
III only
What is output from the following code?
eor
erorg
org
orgi
You will get am index out of bounds exception
Given the following code segment, what is the value of s1 after the code executes?
null
hi there
HI THERE
hI tHERE
Hi There
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?
Data set 2 should return true and one that should return false
The strings in Data Set 2 are all lowercase
All strings in Data Set 2 have the same number of characters
There are no advantages
Data Set 2 contains fewer values than Data Set 1
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?
Use one class, Car, which has three attributes: int numDoors, double mpg, and boolean hasAir.
Use four unrelated classes: Car, Doors, MilesPerGallon, and AirConditioning
Use a class, Car, which has three subclasses: Doors, MilesPerGallon, and AirConditioning
Use a class Car, which has a subclass Doors, with a subclass AC, with a subclass MPG.
Use three classes: Doors, AirConditioning, and MilesPerGallon, each with a subclass Car.
Check MeCompare me
Assume that SomeClass and MainClass are properly defined in separate files. What is the output of the code in main()?
Hello Bob Hello
Hello Bob
Hello Hello Bob
Hello Bob Hello Bob
What is the output of the following code?
Woo Hoo Hoo Woo
Hoo Woo Woo
Woo Woo Hoo Hoo
Woo Hoo Woo Hoo
Woo Hoo Hoo
Given the following code segment, which of the following is true?
II, III, and IV
I, II, III, IV
II and IV
IV only
Check MeCompare me
II only
What does the following code print?
1353
21
Run-time error
138
Compile-time error
Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?
unknown value
Compile Error
0
Run-time Error
Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?
unknown value
0
compile error
runtime error
