AP Computer Science A - Memorization Test

0.0(0)
studied byStudied by 42 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/59

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.

60 Terms

1
New cards

What keyword is used to create a constant?

final

2
New cards

13/5

2

3
New cards

13%5

3

4
New cards

What syntax generates a random integer between 5 and 27 inclusive?

(int)Math.random()*(27-5+1) + 5

5
New cards

What syntax rounds a positive double x to the nearest integer value?

x = (int)(x+.5)

6
New cards

What syntax rounds a negative double x to the nearest integer value?

x=(int)(x-.5)

7
New cards

Arithmetic operations with two ints produces a result of what data type?

an int

8
New cards

Arithmetic operations with at least one double produces a result of what data type?

a double

9
New cards

exception that is thrown if you try to divide by 0

ArithmeticException

10
New cards

The fact that the operator “+” can be used for either addition or concatenation is an example of which OOP principle?

polymorphism

11
New cards

x++; is equivalent to what other line of code?

x=x+1

12
New cards

x*=3; is equivalent to what other line of code?

x=x*3

13
New cards

What are the three escape sequences with which we are required to be familiar?

  • newline: \n

  • quotation marks: \”

  • backslash: \\

14
New cards

How does short-circuit evaluation work with the operator &&?

if the first statement is false Java will automatically return false w/o checking the second statement

15
New cards

How does short-circuit evaluation work with the operator ||?

if the first statement is true Java will automatically return true w/o checking the second statement

16
New cards

State DeMorgan’s Laws

!(A||B) ≡ !A && !B

!(A&&B) ≡ !A||!B

17
New cards

What boolean expression returns true if int x and int y are equal?

x==y

18
New cards

What boolean expression returns true if String x and String y are equal?

x.equsls(y)

19
New cards

What information is included in a method’s signature?

methods name and parameter list

20
New cards

What is the term that refers to writing methods with same name but a different number, type, or sequence of parameters?

overloading methods

21
New cards

The ability to make use of a method without knowing its inner workings is an example of which OOP principle?

abstraction

22
New cards

What keyword is used to instantiate an object?

new

23
New cards

The use of classes is an example of which OOp principle?

encapsulation

24
New cards

What does the keyword public mean?

access is allowed to the declaring class

25
New cards

What does the keyword private mean?

restricts access to the declaring class

26
New cards

Identify whether each of the following should be public or private:

  1. Class

  2. Constructor

  3. Instance Variable

  4. Method

  1. public

  2. public

  3. private

  4. both

27
New cards

term that refers to methods that retrieve the values of class/instance variables

getters/accessor

28
New cards

term that refers to methods that change the values of class/instance variables

setters/mutator

29
New cards

keyword is used to call a constructor with a different number of parameters from within another constructor

this

30
New cards

keyword represents the fact that a variable intended to contain the memory address of an object does not currently contain a memory address

null

31
New cards

What keyword indicates that a single instance of a field is shared by all instances f the class that contains it?

static

32
New cards

How is the syntax for calling a class method (from a runner file) different from the syntax for calling an instance method?

A class method is called using ClassName.methodName() while an instance method is called using nameOfInstance.methodName()

33
New cards

exception that is thrown if you try to call a method on a variable declared to hold an object, but there is no memory address currently stored

NullPointerException

34
New cards

What does it mean when we say that Strings are immutable?

once a string is created they can’t be changed

35
New cards

What exception is thrown if you try to access the element of index -1 in a String?

StringIndexOutOfBoundsException

36
New cards

How do we access the number of characters in a String?

stringName.length()

37
New cards

What can arrays hold?

arrays can hold both objects and primitves

38
New cards

Show the syntax that instantiates an array of any appropriate data type

int [ ] arr = new int [ ]

39
New cards

How do we access the number of elements in an array?

by using a length field (arrayName.length)

40
New cards

What exception is thrown if you try to access the element of index -1 in an array?

ArrayIndexOutOfBoundException

41
New cards

If the contents of the 2-D array myArray are represented by the array below what is the value of myArray [1][2]?

{ 5 1 3 }

{ 4 2 6 }

{ 9 0 8 }

6

42
New cards

The ability of a subclass to automatically gain the attributes of its superclass is an example of which OOP princple?

inheritence

43
New cards

What keyword is used to indicate that a class is a subclass?

extends

44
New cards

Does a subclass inherit fields? constructors? methods?

Fields – generally no, but yes if public (but the subclass always has the fields

of the superclass as attributes!)

Constructors – no

Methods – yes if public, no if private

45
New cards

What keyword is used to call a constructor (or method) of a parent class from a child class?

super()

46
New cards

When calling the constructor of a parent class froma child class, what must you remember?

super should be the first line of code

47
New cards

What does Java do when the constructor of the parent is not called from the constructor of the child

calls the no argument constructors of parent class

48
New cards

What is the superclass of every other class?

Object

49
New cards

What is the term that refers to writing a method in a subclass with the same signature as a method in its superclass?

method overriding

50
New cards

If M in a subclass of N and both have a no-argument constructors, is:

a) M name = new N(); valid syntax?

b) N name = new M(); valid syntax?

a) no

b) yes

51
New cards

What is automatic conversion from a data type to its wrapper class called? What is the reverse called?

autoboxing and unboxing

52
New cards

Can an ArrayList hold (memory addresses) of Objects? Can it hold primitives?

can hold Objects not primitives

53
New cards

Show the syntax that instantiates an Arraylist of any appropriate data type?

ArrayList <String> arr = new ArrayList <String> ();

54
New cards

How do we access the number of elements in an ArrayList?

myArrayList.size();

55
New cards

What exception is thrown if the number of elements in an ArrayList is altered while traversing it with an enhanced for loop?

ConcurrentModificationException

56
New cards

How many iterations of linear/sequential search will it take to find 11 in the array [-3, -1, 0, 4, 11, 8, 5]

5

57
New cards

How many iterations of binary search will it take to find 11 in the array [-3, -1, 0, 4, 5, 8, 11]

3

58
New cards

Show the contents of the array [9, 2, -1, 3, -6, 0, 11, 5] after three iterations of selection sort

[-6, -1, 0, 3, 9, 2, 11, 5]

59
New cards

Show the contents of the array [9, 2, -1, 3, -6, 0, 11, 5] after three iterations of insertion sort

[-1, 2, 3, 9, -6, 0, 11, 5]

60
New cards

Show steps of merge sort on the array [9, 2, -1, 3, -6, 0, 11, 5]

The array is broken into arrays of single elements.

[9], [2], [-1], [3], [-6], [0], [11], [5]

[2, 9], [-1, 3], [-6, 0], [5, 11]

[-1, 2, 3, 9], [-6, 0, 5, 11]

[-6, -1, 0, 2, 3, 5, 9, 11]