ArrayList
For-Each Loop
Basics Classes
Constructors
Static Vs. Instance
100

When should you use an ArrayList?

A.  When storing objects and primitives 

B.  When you need to use a standard for loop

C.  When storing objects

D.  When storing primitive

E.  None of the items listed. 

What is 

C.  When storing objects

100

You need to process an ArrayList and remove several elements in the list. Which loop is most appropriate?

A.  for loop

B.  All loops will work equally.

C.  None of the items listed. 

D.  for-each loop 

E.  You cannot remove elements from an ArrayList.


What is

A.  for loop

100

Which of the following statements about classes is NOT true?

A.  Classes hold more than one piece of data at a time.

B.  Classes hold only one piece of data at a time.

C.  Classes can hold data of different types.

D.  Classes have built in methods, or “tools”.

E.  Users can create their own classes. 

What is

B.  Classes hold only one piece of data at a time.

100

Which of the following is NOT true about constructors?

A.  Constructors have the same name as the class.

B.  Constructors can have parameters.

C.  Constructors are declared using the void keyword.

D.  Constructors never have a void or return type. 

What is 

C.  Constructors are declared using the void keyword.

100

Which of the following is true about static variables?

A.  Static variables are shared among all instances of a class.

B.  Static variables cannot be initialized in a constructor.

C.  Static variables must be declared final.

D.  Static variables can only be accessed by static methods. 

What is

A.  Static variables are shared among all instances of a class.

200

Which of the following is NOT true bout ArrayList objects?

A.  ArrayList is a class data type.

B.  Methods for insertion and deletion are built into the class.

C.  ArrayList objects can only hold class type data.

D.  They can be resized.

E.  ArrayList objects can hold primitive type data. 

 What is

E.  ArrayList objects can hold primitive type data.

200

What can be used to replace /* expression */ so that getTotalChars returns the total number of characters in all the Strings in words? 

What is

s.length();

200

Class data types include variables and ______.

A.  methods

B.  objects

C.  constructors

D.  references

E.  data 

What is

A.  methods

200

The ______ keyword creates an object in memory and assigns the memory reference to the variable.

A.  public

B.  instantiate

C.  private

D.  static

E.  new 

What is 

E.  new

200

Instance variables are variables whose value are specific to an instance of a class.

A. True

B. False 

What is

A. True

300

What is output by this code?

What is 

  [shirt, sock, sweater, shorts]


300

Write a loop that will correctly print every element of nums which is greater than 10, but none of the other integers contained in nums? 

What is

300

All instance variables should be declared as _______

A.  primitives

B.  objects

C.  arrays

D.  public

E.  private 

What is

E.  private

300

What is true about constructor?
A.  It can contain return type
B.  It can take any number of parameters
C.  It can have any non access modifiers
D.  Constructor cannot throw an exception

What is

B.  It can take any number of parameters

300

In a gas station class, which of the following variables would be static?

A.  Customer bill

B.  Gas Price

C.  Customer

D.  Vehicle 

What is

B.  Gas Price

400

Which is the correct import statement for the ArrayList class?

A.   import java.awt.ArrayList

B.   import java.io.ArrayList

C.   import java.util.ArrayList

D.   import java.ArrayList

E.   import util.io.ArrayList 

What is 

C.   import java.util.ArrayList

400

What is output?

What is

MOUSE
SPEAKERS
SCANNER
SCREEN

400

The ______ methods are used to change variables in classes, while the ______ methods are used to return the data.

A.  mutator, accessor

B.  accessor, mutator 

What is

A.  mutator, accessor

400

What is true about private constructors?
A.  Private constructor ensures only one instance of a class exist at any point of time
B.  Private constructor ensures multiple instances of a class exist at any point of time
C.  Private constructor eases the instantiation of a class
D.  Private constructor allows creating objects in other classes

What is 

A.  Private constructor ensures only one instance of a class exist at any point of time

400

You are writing a class for a chain of businesses with the same hours. Which of the following would you want to make static?

A.  A boolean to determine if the stores are opened or closed.

B.  A double to hold store revenue.

C.  A String to hold store phone number.

D.  A String to hold business location. 

What is

A.  A boolean to determine if the stores are opened or closed.

500

What is printed as a result of executing  "System.out.println(sequence(5));"

What is

 [5, 7, 9, 11, 13]

500

The method timesContained is intended to return the number of times the string str is contained in the ArrayList words. What code can replace /* missing expression */ so that timesContained works as intended?

What is

500

Suppose nums = {0, 3, 1, 1, 1, 6, 6}. What is returned by the call repeatHelper(3)?

What is

3

500

The line, stack.add(new Box()); calls the ______ of Box. 

A.  equals method

B.  static method

C.  toString

D.  default constructor

E.  mutator


What is

D.  default constructor

500

Which of these cannot be declared static?
A.  class
B.  object
C.  variable
D.  method

What is 

B.  object

M
e
n
u