exam 2 jv
Subscripting always starts with ________.
0
tells the Java compiler that a method is meant to override a method in the superclass.
@Override
Which of the following is TRUE about protected access?
B) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package
Each array in Java has a public field named ________ that contains the number of elements in the array.
Length
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
NOT the values for each field
Instance methods do not have the __________ key word in their headers.
Static
Why can't this be used in static methods?
Static methods are not called using an object. Thus, this would be null.
If the this variable is used to call a constructor:
a compiler error will result, if it is not the first statement of the constructor
What is a ragged array?
a two-dimensional array where the rows have a different number of columns
Which of the following statements is true?
a)Methods and instance variables can be public, protected or private.
A class that implements an interface but does not declare all of the interface's methods must be declared ________.
abstract
A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.
abstract
A(n) class cannot be instantiated.
abstract
A static field is created by placing the key word static
after the access specifier and before the field's data type
All fields declared in an interface
are treated as final and static
For which of the following would polymorphism not provide a clean solution? a. A billing program where there is a variety of client types that are billed with different fee structures. b. A maintenance log program where data for a variety of types of machines is collected and maintenance schedules are produced for each machine based on the data collected. c. A program to compute a 5% savings account interest for a variety of clients. d. An IRS program that maintains information on a variety of taxpayers and determines who to audit based on criteria for classes of taxpayers.
c. A program to compute a 5% savings account interest for a variety of clients.
Polymorphism allows for specifics to be dealt with during:
execution
What is the keyword required to use Interfaces(case sensitive)
implements
in java, you do not use the new operator when you use a(n):
initialization list
Which of the following is a valid declaration for a ragged array with five rows, but no columns?
int[][] ragged = new int[5][];
A deep copy of an object:
is an operation that copies an aggregate object, and all the objects it references
A search algorithm
is used to locate a specific item in a larger collection of data
When an array is passed to a method
it is passed just as any other object would be. the method has direct access to the original array. a reference to the array is passed. All of these
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?
numbers[r].length
When a field is declared static, there will be:
only one copy of the field in memory
A subclass can directly access
only protected and private members of the superclass
This enum method returns the position of an enum constant in the declaration.
ordinal
Instance variables or methods declared with which modifier are accessible only in that class definition?
private
Polymorphism enables you to
program in the general
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passMyArray(int[][] myArray)
What is the "this" keyword used to reference?
references the object that called the method.
The method removes an item from an ArrayList at a specific index.
remove
You can use this ArrayList class method to replace an item at a specific location in an ArrayList.
set
You use this method to determine the number of items stored in an ArrayList object.
size
In order to do a binary search on an array,
the array must first be sorted in ascending order.
When an individual element of an array is passed to a method
the method does not have direct access to the original array
This method returns a string representing all of the items stored in an ArrayList object.
toString
If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.
true
Java performs array bounds checking, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for an array.
true
To determine if two arrays are equal, you must compare each of the elements of the two arrays.
true
The binary search algorithm
will cut the portion of the array being searched in half each it fails to locate the search value.
To compare two objects in a class,
write an equals method that will make a field by field compare of the two objects