AP CSA 5.6/5.7 (Methods & Static)

AP CSA 5.6/5.7 (Methods & Static)

10th Grade

5 Qs

quiz-placeholder

Similar activities

AP CSP Code.org Unit 7

AP CSP Code.org Unit 7

9th - 12th Grade

8 Qs

AP CSP Conditionals

AP CSP Conditionals

9th - 12th Grade

7 Qs

Wrong Answers Only CSP

Wrong Answers Only CSP

9th - 12th Grade

10 Qs

Code.org Unit 5 Vocab Quiz 1

Code.org Unit 5 Vocab Quiz 1

9th - 12th Grade

10 Qs

Python Variables

Python Variables

7th - 12th Grade

10 Qs

AP CS A Unit 6 Quiz PRACTICE

AP CS A Unit 6 Quiz PRACTICE

9th - 12th Grade

10 Qs

HTML Forms

HTML Forms

9th - 12th Grade

10 Qs

AP Computer Science Principles Unit 7 Review

AP Computer Science Principles Unit 7 Review

9th - 12th Grade

8 Qs

AP CSA 5.6/5.7 (Methods & Static)

AP CSA 5.6/5.7 (Methods & Static)

Assessment

Quiz

Computers

10th Grade

Hard

Created by

Herman Galioulline

Used 19+ times

FREE Resource

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

Consider the following class declaration. The changeWeather method is intended to update the value of the instance variable weather and return the previous value of weather before it was updated.


Which of the following options should replace /* missing code */ so that the changeWeather method will work as intended?

String prev = w;

return weather;

String prev = weather;

return w;

String prev = w;

return prev;

weather = w;

String prev = weather;

return prev;

String prev = weather;

weather = w;

return prev;

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

The isGreater method is intended to return true if the value of one for this BoolTest object is greater than the value of one for the BoolTest parameter other, and false otherwise. The following code segments have been proposed to replace /* missing code */.


I. return one > other.one;

II. return one > other.getOne();

III. return getOne() > other.one;


Which of the following replacements for /* missing code */ can be used so that isGreater will work as intended?

I only

II only

III only

I and II only

I, II, and III

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

The code segment does not compile because the setStatus method should be called on an object of the class Gadget, not on the class itself.

The code segment does not compile because the static variable status is not properly initialized.

The code segment creates two Gadget objects a and b. The class Gadget’s static variable status is set to 10, then to 3, and then back to 10.

The code segment creates two Gadget objects a and b. After executing the code segment, the object a has a status value of 3 and the object b has a status value of 3.

The code segment creates two Gadget objects a and b. After executing the code segment, the object a has a status value of 3 and the object b has a status value of 10.

4.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

Both numOunces and numSold can be accessed and updated.

Both numOunces and numSold can be accessed, but only numOunces can be updated.

Both numOunces and numSold can be accessed, but only numSold can be updated.

numSold can be accessed but not updated; numOunces cannot be accessed or updated.

numSold can be accessed and updated; numOunces cannot be accessed or updated.

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Media Image

The following class is used to represent shipping containers. Each container can hold a number of units equal to unitsPerContainer.


The following code segment appears in a method in a class other than UnitsHandler. Assume that no other code segments have created or modified UnitsHandler objects.


UnitsHandler large = new UnitsHandler(100);


UnitsHandler.update(8);


Which of the following best describes the behavior of the code segment?

The code segment does not compile, because it is not possible to create the object large from outside the UnitsHandler class.

The code segment does not compile, because it attempts to change the values of private variables from outside the UnitsHandler class.

The code segment does not compile, because the update method should be called on the object large instead of on the UnitsHandler class.

The code segment creates a UnitsHandler object called large and sets the static variable unitsPerContainer to 100. The static variables containers and totalUnits each retain the default value 0.

The code segment creates a UnitsHandler object called large and sets the static variables unitsPerContainer, containers, and totalUnits to 100, 8, and 800, respectively.