Search Header Logo

AP CSA 5.6/5.7 (Methods & Static)

Authored by Herman Galioulline

Computers

10th Grade

Used 21+ times

AP CSA 5.6/5.7 (Methods & Static)
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?