Search Header Logo

AP CSA Unit 2 Test review - Missed Questions

Authored by Wayground Content

Computers

11th Grade

Used 1+ times

AP CSA Unit 2 Test review - Missed Questions
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

11 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 5 pts

Media Image

The code segment below is intended to randomly print one of the values 2, 4, 6, or 8 with equal probability.

Which of the following can be used to replace /* missing code */ so that the code segment works as intended?

Math.random() * 4 + 1

Math.random() * 8

(int) (Math.random() * 4)

(int) (Math.random() * 4 + 1)

(int) (Math.random() * 8 + 1)

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method.


public double calculate(double x)

{

return x + 1.5;

}


The following code segment calls the method calculate in the same class.


Double d1 = new Double(7.5);

System.out.println(calculate(d1));


What, if anything, is printed when the code segment is executed?

8.0

8.5

9

9.0

Nothing is printed because the code does not compile. The actual parameter d1 passed to calculate is a Double, but the formal parameter x is a double.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

__________ refers to the act of representing essential details.

Polymorphism

Abstraction

Inheritance

Encapsulation

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Main() method is not mandatory for a Java program

True

False

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is an example of encapsulation in Java?

Declaring instance variables as private and providing public getter and setter methods

Overloading methods with different parameters

Creating multiple constructors in a class

Using inheritance to extend a class

6.

MULTIPLE CHOICE QUESTION

30 sec • 5 pts

Media Image

Consider the following code segment, which is intended to display 6.0.

Which of the following best describes the error, if any, in the code segment?

There are no errors and the code works as intended.

Either the numerator or the denominator of the fraction 1 / 2 should be cast as double.

The expression fact1 * fact 2 should be cast as double.

The expressions 1 / 2 and 3 * 4 should both be cast as double.

The variables fact1 and fact2 should both be declared as int.

7.

MULTIPLE CHOICE QUESTION

30 sec • 5 pts

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

int len = length(txt);

float len = txt.length();

int len = txt.length();

double len = length(txt);

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?