AP CSA Midterm

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/53

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

54 Terms

1
New cards

What is output with the statement System.out.println(““+x+y); if x and y are int values where x=10 and y=5?

105

2
New cards

Use the following class definition to answer the following question.

public class Questions1_4 {

    public static void main(String[] args) {

        System.out.print("Here");

        System.out.println("There " + "Everywhere");

        System.out.println("But not" + "in Texas");

    }

}

// a program that demonstrates the differences between print, println, and how + works

3
New cards

An error in a program that results in the program outputting $100 instead of the correct answer, $250 is

a logical error

4
New cards

Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following?

if (count != 0 && total / count > max) max = total / count;

The condition short circuits and the assignment statement is not executed

5
New cards

In order to determine the type that a polymorphic variable refers to, the decision is made

by the Java run-time environment at run time

6
New cards
<p>Which of the following lists of instance data are accessible in A3?</p>

Which of the following lists of instance data are accessible in A3?

x, z, a, q

7
New cards
<p>Which of the following is true regarding the use of instance variable y of class A1?</p>

Which of the following is true regarding the use of instance variable y of class A1?

it is accessible only in A1

8
New cards

If a method does not have a return statement, then

it must be a void method

9
New cards

In order to preserve encapsulation of an object, we would do all of the following except for which one?

Make the class final

10
New cards

A variable whose scope is restricted to the method where it was declared is known as a(n)

local variable

11
New cards
<p>Assume values is an int array that is currently filled to capacity, with the values:<br><br>The statement System.out.pringln(values[7]); will</p>

Assume values is an int array that is currently filled to capacity, with the values:

The statement System.out.pringln(values[7]); will

cause an ArrayOutOfBoundsException to be thrown

12
New cards

What is a mutator method?

A method that modifies a value

13
New cards
<p>Consider the following class definition:<br><br>If q1 and q2 are objects of Q, then q1.equals(q2)</p>

Consider the following class definition:

If q1 and q2 are objects of Q, then q1.equals(q2)

is true if q1 and q2 reference the same Q object

14
New cards

What will be the result of the following assignment statement? Assume b = 5 and c = 10.

int a = b * (-c + 2)/2;

-20

15
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values:<br><br>What is returned by values[3]?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

What is returned by values[3]?

2

16
New cards

A class’ constructor usually defines

how an object is initialized

17
New cards

Assume that x,y, and z are all ints equal to 50, 20, and 6 respectively. What is the result of x/y/z?

0

18
New cards

For this question, refer to the class defined below:

import java.util.Scanner;

public class Questions {

    public static void main(String[] args) {

        int x, y, z;

        double average;

        Scanner scan = new Scanner(System.in);

        System.out.println("Enter an integer value");

        x.scan.nextInt();

        System.out.println("Enter another integer value");

        y.scan.nextInt();

        System.out.println("Enter a third integer value");

        z.scan.nextInt();

        average = (x + y + z) / 3;

        System.out.println("The result of my calculation is " + average);

    }

}

What is the output if x = 0, y = 1, and z = 1?

0.0

19
New cards

All classes in Java are directly or indirectly subclasses of the ______ class

Reference

20
New cards

Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending on a student's test score.

if(score >= 90) grade = 'A';

if(score >= 80) grade = 'B';

if(score >= 70) grade = 'C';

if(score >= 60) grade = 'D';

else grade = 'F';

This code will work correctly only if score < 70

21
New cards

Forgetting a semicolon will cause

a syntax error

22
New cards

Of the following if statements, which one correctly executes three instructions if the condition is true?

 if (x < 0)

     {

          a = b * 2;

          y = x;

          z = a - y;

}

23
New cards

Which of the following would be a legal Java identifier?

i

24
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values:<br><br>Which of the following loops would adequately add 1 to each element stored in values?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

Which of the following loops would adequately add 1 to each element stored in values?

for(j=0;j<=values.length;j++) values[j]++;

25
New cards

If you want to output the text “hi there,” including quote marks, which of the following could do that?

System.out.println("\"hi there\"");

26
New cards

Which of the following reserved words in Java is used to create an instance of a class?

new

27
New cards

For the following question, refer to the class below:

import java.util.Scanner;

public class Questions {

    public static void main(String[] args) {

        int x, y, z;

        double average;

        Scanner scan = new Scanner(System.in);

        System.out.println("Enter an integer value");

        x.scan.nextInt();

        System.out.println("Enter another integer value");

        y.scan.nextInt();

        System.out.println("Enter a third integer value");

        z.scan.nextInt();

        average = (x + y + z) / 3;

        System.out.println("The result of my calculation is " + average);

    }

}

 

Questions computes

The average of x, y, and z as a double, but the result may not be accurate

28
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values:<br><br>What is the value of values.length?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

What is the value of values.length?

7

29
New cards
<p>Consider the following class definition:<br><br>Which of the following is true about the class Q?</p>

Consider the following class definition:

Which of the following is true about the class Q?

it’s parent class is Object

30
New cards

Having multiple class methods of the same name where each method has a different number of or type of parameters is known as

method overloading

31
New cards

Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?

          for(int i=0;i<5;i++)

               x += i;

10

32
New cards

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?

if (x > 0) x++;

else if (x < 0) x--;

33
New cards

The instruction super(); does which of the following?

calls the constructor as defined in the current class' parent class

34
New cards

The behavior of an object is defined by the object's

methods

35
New cards

What value will z have if we execute the following assignment statement?

     double z = 5 / 10;

z will equal 0.0

36
New cards

Use the following class definition to answer the following question.

public class Questions1_4 {

    public static void main(String[] args) {

        System.out.print("Here");

        System.out.println("There " + "Everywhere");

        System.out.println("But not" + "in Texas");

    }

}

How many lines of output are provided by this program?

2

37
New cards

A case is required in which of the following situations?

storing a double in an int

38
New cards

Which character below is not allowed in an identifier?

^

39
New cards

The relationship between a class and an object is best described as

objects are instances of classes

40
New cards

Consider the following statement:

System.out.println(“1 big bad wold\t8 the 3 little pigs\n4dinner\r2night”)';

The statement will output__ lines of text.

2

41
New cards
<p>Which of the following lists of instance data are accessible in class A2?</p>

Which of the following lists of instance data are accessible in class A2?

x, z, a, b

42
New cards

To define a class that will represent a car, which of the following definitions is most appropriate?

public class Car

43
New cards

Which of the following would be a good variable name for the current value of a stock?

currentStockVal

44
New cards

If you want to store into the String name the value “George Bush” you would use which statement?

Any of the above would work

45
New cards

Comments should

be insightful and explain what the instruction’s intent is

46
New cards

Use the following class definition to answer the following definition.

public class Questions1_4 {

    public static void main(String[] args) {

        System.out.print("Here");

        System.out.println("There " + "Everywhere");

        System.out.println("But not" + "in Texas");

    }

}

 

The final println command will output

“But notin Texas”

47
New cards

Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

foo(0 / 1.2 * 3);

48
New cards

Use the following class definition to answer the following question.

public class Questions1_4 {

    public static void main(String[] args) {

        System.out.print("Here");

        System.out.println("There " + "Everywhere");

        System.out.println("But not" + "in Texas");

    }

}

 

 

The program will print the word "Here" and then print

“There Everywhere” on the same line as “Here”

49
New cards

Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

Math.sqrt(Math.abs(x));

50
New cards

Following Java naming convention, which of the following would be the best name for a class about store customers?

StoreCustomer

51
New cards

Which of the following is a legal Java identifier?

oneForAll

52
New cards

The “off-by-one” error associated with arrays arises because

the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far

53
New cards

Given the following assignment statement, which of the following answers is true regarding the order that the operators will be applied based on operator precedence?

     a = (b + c) * d / e - f;

+,*,/,-

54
New cards
<p><span>Which of the following is true with respect to A1, A2 and A3?</span></p>

Which of the following is true with respect to A1, A2 and A3?

A3 is a subclass of A2 and A2 is a subclass of A1