JAVA Final (NVCC)
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
The objects memory address
A method that stores a value in a class's field or in some other way changes the value of a field is known as the mutator method. True or False?
True
Declaring an array reference variable does not create an array. True or False?
True
Objects in an array are accessed with subscripts, just like any other data type in an array. True or False
True
Once an array is created, its size cannot be changed. True or False?
True
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line. True or False?
True
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by:
Using the private access specifier on the class's fields
Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the ordinal value of the MAPLE enum constant? a. 0 b. 1 c. 2 d. 3
b. 1
What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov"); a. 14 b. 15 c. 18 d. 17
b. 15
If you attempt to perform an operation with a null reference variable __________. ifa. the resulting operation will always be zero b. the results will be unpredictable c. the program will terminate d. Java will create an object to reference the variable
c. the program will terminate
If a class contains an abstract method __________. a. you must create an instance of the class b. the method will only have a header, but not a body, and will end with a semicolon c. the method cannot be overridden in subclasses d. All of these are true.
b. the method will only have a header, but not a body, and will end with a semicolon
The names of the enum constants in an enumerated data type must be enclosed in quotation marks. True or False?
False
Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; a. The numbers array has 54 rows. b. The numbers array has 15 rows. c. The numbers array has 6 rows and 9 columns. d. The numbers array has 6 columns and 9 rows.
d. The numbers array has 6 columns and 9 rows.
It is common practice to use a __________ variable as a size declarator. a. static c. final b. reference d. boolean
final
You should not define a class that is dependent on the values of other class fields__________
in order to avoid stale data
Another term for an object of a class is a(n)
instance
Methods that operate on an object's fields are called __________.
instance methods
A reference variable stores a(n) __________.
memory address
A group of related classes is called a(n)
package
When you work with a __________, you are using a storage location that holds a piece of data.
primitive variable
Instance methods do not have the __________ key word in their headers.
static
__________ refers to combining data and code into a single object.
Encapsulation
Java limits the number of dimensions that an array can have to 15. True or False?
False
The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value. True or False
False
The following statement correctly creates a StringBuilder object. StringBuilder str = "Tuna sandwich"; True or False?
False
The scope of a private instance field is __________.
The instance method of the same class
An enumerated data type is actually a special type of class. True or False?
True
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable. True or False?
True
It is common practice in object-oriented programming to make all of a class's __________.
fields private
Methods that operate on an object's fields are called:
instance methods
A UML diagram does not contain __________.
object names
Most of the programming languages used today are __________.
object oriented
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?
b. numbers.length[r]
The __________ key word is used to call a superclass constructor explicitly. a. goto b. this c. super d. extends
c. super
Java allows you to create objects of the __________ class in the same way you would create primitive variables.
String
Most of the String comparison methods are case sensitive. True or False?
True
The key word this is the name of a reference variable that an object can use to refer to itself. True or False?
True
The term "no-arg-constructor" is applied to any constructor that does not accept arguments. True or False?
True
enum constants have a toString method. True or False?
True
What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; } a. 170 b. 180 c. 190 d. 200
b. 180
The __________ method of the String class can be used to tokenize a string. a. split b. tokenize c. trim d. length
b. tokenize
The scope of a public instance field is __________.
the instance methods and methods outside the class
__________ is the term for the relationship created by object aggregation. a. "Has a" c. "Is a" b. Inner class d. One-to-many
a. "Has a"
Java automatically stores a __________ value in all uninitialized static member variables. a. 0 b. -1 c. null d. false
a. 0
What are the tokens in the following code? String str = "123-456-7890"; String[] tokens = str.split("-"); a. 123, 456,7890 c. - b. 123, 456, 7890,- d. None of these
a. 123, 456, 7890
An exception object's default error message can be retrieved using the __________ method. a. getMessage c. getDefaultErrorMessage b. getDefaultMessage d. getErrorMessage
a. getMessage
An object's __________ is simply the data that is stored in the object's fields at any given moment. a. value c. record b. assessment d. state
d. state
What would be the results of executing the following code? StringBuilder str = new StringBuilder("Little Jack Horner "); str.append("sat on the "); str.append("corner"); a. The program would crash. b. str would reference "Little Jack Horner ". c. str would reference "Little Jac Horner sat on the ". d. str would reference "Little Jack Horner sat on the corner".
d. str would reference "Little Jack Horner sat on the corner".
A class specifies the __________ and __________ that a particular type of object has.
fields; methods
If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector. True or False?
False
When you make a copy of the aggregate object and of the objects that it references, __________. a. you are performing a shallow copy b. you are performing a nested copy c. you are performing a deep copy d. a compiler error will occur
c. you are performing a deep copy
To indicate the data type of a variable in a UML diagram, you enter __________.
the variable name followed by a colon and the data type
What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a]; } a. value contains the highest value in array1. b. value contains the lowest value in array1. c. value contains the sum of all the values in array1. d. This code would cause the program to crash.
c. value contains the sum of all the values in array1.
What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; } a. value contains the highest value in array1. b. value contains the lowest value in array1. c. value contains the sum of all the values in array1. d. This code would cause the program to crash.
d. This code would cause the program to crash.
All fields declared in an interface __________. a. have protected access b. must be initialized in the class implementing the interface c. have private access d. are treated as final and static
d. are treated as final and static
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
A single copy of a class's static field is shared by all instances of the class. True or False?
True
Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones. True or False?
True
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 or False?
True
If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString()); True or False
True
Instance methods do not have the key word static in their headers. True or False?
True
It is not possible for a superclass to call a subclass's method. True or False
True
The java.lang package is automatically imported into all java programs. True or False?
True
The wrapper classes in Java are immutable, which means that once you create an object, you cannot change the object's value. True or False?
True
To determine if two arrays are equal you must compare each of the elements of the two arrays. True or False?
True
Trying to extract more tokens than exist from a StringTokenizer object will cause an error. True or False?
True
When a subclass extends a superclass, the public members of the superclass become public members of the subclass. True or False
True
When working with the String and StringBuilder classes' getChars method, the character at the start position is included in the substring but the character at the end position is not included. True or False
True
You can change the contents of a StringBuilder object, but you cannot change the contents of a String object. True or False?
True
The whole-part relationship created by object aggregation is more often called a(n) __________ relationship. a. "has a" c. extra class b. inner class d. inside class
a. "has a"
After the header, the body of the method appears inside a set of __________. a. braces, { } c. brackets, [ ] b. parentheses, ( ) d. double quotes, " "
b. a. braces, {}
Which symbol indicates that a member is public in a UML diagram?
+
By default, Java initializes array elements to __________. a. 0 b. 100 c. -1 d. 1
0
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable. True or False?
False
You cannot assign a value to a wrapper class object. True or False
False
When an object is created, the attributes associated with the object are called
Instance fields
What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); m++; } a. abc456 b. ABC456 c. ABC d. 456
c. ABC
A constructor __________.
has the same name as the class
The __________ package is automatically imported into all Java programs.
java.lang
Every class has a toString method and an equals method inherited from the Object class. True or False?
True
If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. True or False?
True
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged. True or False?
True
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token. True or False?
True
In Java, a reference variable is __________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance. a. static b. dynamic c. polymorphic d. public
c. polymorphic
The sequential search algorithm __________. a. returns 1 if the value being searched for is found or -1 if the value is not found b. requires the array to be ascending order c. uses a loop to sequentially step through an array, starting with the first element d. must always be implemented as a method
c. uses a loop to sequentially step through an array, starting with the first element
The String class's __________ method accepts a value of any primitive data type as its argument and returns a string representation of the value. a. trim b. getChar c. toString d. valueOf
d. valueOf
The key word this is the name of a reference variable that is available to all static methods. True or False?
False
Which of the following statements will create a reference, str, to the String "Hello, World"? a. String str = "Hello, World"; b. string str = "Hello, World"; c. String str = new "Hello, World"; d. str = "Hello, World";
String str = "Hello, World";
A functional interface is simply an interface that has one abstract method. True or False?
True
An instance of a class does not have to exist in order for values to be stored in a class's static fields. True or False?
True
An object can store data. True or False?
True
Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created. True or False?
True
Java does not limit the number of dimensions an array may have. True or False?
True
StringBuilder objects are not immutable. True or False
True
The String class's regionMatches method performs a case-insensitive comparison. True or False?
True
When an array of objects is declared but not initialized, the array values are set to null. True or False?
True
When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable. True or False?
True
When an object is passed as an argument, it is actually a reference to the object that is passed. True or False?
True
When an object reference is passed to a method, the method may change the values in the object. True or False?
True
You can declare an enumerated data type inside a method. True or False
True
You can write a super statement that calls a superclass constructor but only in the subclass's constructor. True or False?
True
What does the following UML diagram mean?
a public method with a parameter of data type double that does not return a value
What type of relationship exists between two objects when one object is a specialized version of another object? a. "is a" c. "has a" b. "contains a" d. "consists of"
a. "is a"
Subscripting always starts with __________. a. 0 b. 1 c. -1 d. none of these
a. 0
__________ tells the Java compiler that a method is meant to override a method in the superclass. a. @Override c. @Protected b. @Overload d. @Inherited
a. @Override
Autoboxing is __________. a. Java's process of automatically "boxing up" a value inside an object b. the automatic allocation of array elements c. the process of assigning a default value to primitive data types d. the process of identifying tokens in a string
a. Java's process of automatically "boxing up" a value inside an object
For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; } a. The z field is available to code written outside the Sphere class. b. The radius field is not available to code written outside the Sphere class. c. The radius, x, y, and z fields are members of the Sphere class. d. The x field is available to code that is written outside the Sphere class.
a. The z field is available to code written outside the Sphere class.
If the following is from the method section of a UML diagram, which of the statements below is true? + equals(object2:Stock) : boolean a. This is a public method that accepts a Stock object as its argument and returns a boolean value. b. This is a public method that returns a reference to a String object. c. This is a private method that receives two objects from the Stock class and returns a boolean value. d. This is a private method that returns a boolean value.
a. This is a public method that accepts a Stock object as its argument and returns a boolean value.
What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder("We have lived in Chicago, Trenton, and Atlanta."); strb.replace(17, 24, "Tampa"); System.out.println(strb); a. We have lived in Tampa, Trenton, and Atlanta. b. We have lived in Chicago, Trenton, and Tampa. c. We have lived in Chicago,Tampaon, and Atlanta. d. We have lived in Chicago, Tampa, and Atlanta.
a. We have lived in Tampa, Trenton, and Atlanta.
What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; a. a = 5 b. a = 8 c. a = 10 d. a = 13
a. a = 5
You cannot use the fully-qualified name of an enum constant for ___________. a. a case expression c. a boolean expression b. an argument to a method d. Any of these
a. a case expression
If the this variable is used to call a constructor, __________. cons a. a compiler error will result if it is not the first statement of the constructor b. a compiler error will result if it is the first statement of the constructor c. nothing will happen d. the this variable cannot be used as a constructor call
a. a compiler error will result if it is not the first statement of the constructor
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; a. a reference to the String object containing "ghi" b. "ghi" c. a reference to the String object containing "def" d. "def"
a. a reference to the String object containing "ghi"
A(n) __________ method is a method that appears in a superclass but expects to be overridden in a subclass. a. abstract b. protected c. static d. overloaded
a. abstract
The following statement is an example of __________. import java.util.Scanner; a. an explicit import statement b. an unconditional import statement c. a wildcard import statement d. a conditional import statement
a. an explicit import statement
An exception's default error message can be retrieved by using the __________ method. a. getMessage() b. getErrorMessage() c. getDefaultMessage() d. getDefaultErrorMessage()
a. getMessage()
When the this variable is used to call a constructor__________. a. it must be the first statement in the constructor making the call b. it can be anywhere in the constructor making the call c. it must be the last statement in the constructor making the call d. None of these. You cannot use the this variable in a constructor call.
a. it must be the first statement in the constructor making the call
__________ is a special type of expression used to create an object that implements a functional interface. a. lambda b. beta c. alpha d. sigma
a. lambda
Any ___________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is. a. nonletter b. char c. string d. static
a. nonletter
You cannot use the == operator to compare the contents of __________. a. objects c. integers b. strings d. Boolean values
a. objects
What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens) System.out.print(s + " "); a. red green blue orange b. red $ green & blue # orange c. $ & # d. red[$&#]green[$&#]blue[$&#]orange
a. red green blue orange
The __________ method removes an item from an ArrayList at a specific index. a. remove b. pop c. deleteAt d. clear
a. remove
You can use the __________ method to replace an item at a specific location in an ArrayList.
a. set
The process of breaking a string down into tokens is known as __________. a. tokenizing b. buffering c. simplifying d. parsing
a. tokenizing
Static methods can only operate on __________ fields. a. instance c. global b. static d. local
b. Static
Given the following, which of the statements below is not true? str.insert(8, 32); a. str is a StringBuilder type object. b. The insert will start at position 32. c. The starting position for the insert is 8. d. The literal number 32 will be inserted.
b. The insert will start at position 32.
When a method's return type is a class, what is actually returned to the calling program? a. an object of that class b. a reference to an object of that class c. the values in the object that the method accessed d. nothing - the return type is simply for documentation in this situation
b. a reference to an object of that class
A static field is created by placing the key word static __________. a. after the access specifier and the field's data type b. after the access specifier and before the field's data type c. after the field name d. in brackets, before the field's data type
b. after the access specifier and before the field's data type
Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array. a. active array sequencing b. array bounds checking c. scope resolution binding d. buffer overrun protection
b. array bounds checking
The __________ indicates the number of elements the array can hold. a. new operator b. array's size declarator c. array's data type d. version of Java
b. array's size declarator
You can concatenate String objects by using the __________. a. concat or trim methods b. concat method or the + operator c. concatenate or join methods d. concatenate method or the + operator
b. concat method or the + operator
The term used for the character that separates tokens is __________. a. tokenizer b. delimiter c. whitespace d. separator
b. delimiter
What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17); a. diddle b. diddl c. didd d. iddle
b. diddl
Which of the following statements will convert the string, str = "285.74" to a double? a. double x = str; b. double x = Double.parseDouble(str); c. double x = Double.Double(str); d. double x = str.Double.parseDouble;
b. double x = Double.parseDouble(str);
In Java, you do not use the new operator when you use a(n) ____________. a. array size declarator b. initialization list c. two-dimensional array d. any of these
b. initialization list
Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1(); a. method1 on Line 4 b. method1 on Line 9 c. method1 on Line 14 d. This is an error and will cause the program to crash.
b. method1 on line 9
What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches); a. true b. moon c. false d. The cow
b. moon
The Character wrapper class provides numerous methods for __________. a. converting objects to primitive data types b. testing and converting character data c. testing and converting numeric literals d. performing operations with named constants
b. testing and converting character data
When a reference variable is passed as an argument to a method __________. a. a copy of the variable's value is passed into the method's parameter b. the method has access to the object that the variable references c. the method becomes a static method d. the program terminates
b. the method has access to the object that the variable references
In an inheritance relationship __________. a. the subclass constructor always executes before the superclass constructor b. the superclass constructor always executes before the subclass constructor c. the constructor with the lowest overhead always executes first regardless of inheritance in subclasses d. the unified constructor always executes first regardless of inheritance
b. the superclass constructor always executes before the subclass constructor
The only limitation that static methods have is __________. a. they must be declared outside of the class b. they cannot refer to nonstatic members of the class c. they can only be called from static members of the class d. they can refer only to nonstatic members of the class
b. they cannot refer to nonstatic members of the class
A series of words or other items of data, separated by spaces or other characters, is known as a __________. a. string b. token c. delimiter d. caption
b. token
The __________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted. a. remove b. trim c. compress d. concat
b. trim
The process of converting a wrapper class object to a primitive type is known as __________. a. simplifying b. unboxing c. parsing d. devaluating
b. unboxing
What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; } a. value contains the highest value in array1 b. value contains the lowest value in array1 c. value contains the sum of all the values in array1 d. value contains the average of all the values in array1
b. value contains the lowest value in array1
The binary search algorithm __________. a. is less efficient than the sequential search algorithm b. will cut the portion of the array being searched in half each time it fails to locate the search value c. will have a maximum number of comparisons equal to the number of elements in the array d. will, normally, have the number of comparisons that is half the number of elements in the array
b. will cut the portion of the array being searched in half each time it fails to locate the search value
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; } a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} c. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} d. Nothing. This is a compile error.
b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x; a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} c. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} d. Nothing. This is a compile error.
b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
A class's responsibilities include
both the things a class is responsible for doing and the things a class is responsible for knowing
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]? a. 1 through 15 c. 0 through 14 b. 1 through 14 d. 0 through 15
c. 0 through 14
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold __________ characters. a. 0 b. 8 c. 16 d. 32
c. 16
What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.CharAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); } a. ABC b. ABC456 c. 456 d. abc456
c. 456
What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; } a. 50 b. 55 c. 60 d. 65
c. 60
What is the value of scores[2][3] in the following array? int[][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; a. 95 b. 84 c. 94 d. 93
c. 94
The __________ class is the wrapper class for the char data type. a. StringBuilder c. Character b. Integer d. String
c. Character
When an individual element of an array is passed to a method __________. a. a reference to the array is passed b. it is passed like any other variable c. the method does not have access to the original array d. All of these are true.
c. The method does not have direct access to the array
A declaration for an enumerated type begins with the __________ key word. a. enumerated c. ENUM b. enum type d. enum
c. enum
If str is declared as: String str = "ABCDEFGHI"; What will be returned from the following statement? Character.toLowerCase(str.charAt(5)) a. e b. E c. f d. F
c. f
Enumerated types have the __________ method which returns the position of an enum constant in the declaration list. a. position c. ordinal b. location d. index
c. ordinal
The term __________ is commonly used to refer to a string that is part of another string. a. nested string b. literal c. substring d. delimiter
c. substring
The ________ character appears at the end (the right side) of a string, after the non-space characters. a. leading whitespace c. trailing whitespace b. character return d. line feed
c. trailing whitespace
What is the term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables? a. intrinsic class c. wrapper class b. enclosed object d. transitional object
c. wrapper class
In the following code, how many times will the for loop execute? String str = ("Ben and Jerry's ice cream is great."); String[] tokens = str.split(" "); for (String s : tokens) System.out.println(s); a. 1 b. 3 c. 5 d. 7
d. 7
In the following code, how many times will the for loop execute? String str = "1,2,3,4,5,6,7,8,9"); String[] tokens = str.split(","); for (String s : tokens) System.out.println(s); a. 1 b. 5 c. 7 d. 9
d. 9
The StringBuilder class's insert method allows you to insert a(n) __________ into the calling object's string. a. char array c. String object b. primitive type d. All of these
d. All of these
When an array is passed to a method __________. a. it is passed just as any other object would be passed b. the method has direct access to the original array c. a reference to the array is passed d. All of these are true
d. All of these are true
In Java it is possible to write a method that will return __________. a. a whole number c. a string of characters b. a reference to an object d. Any of these
d. Any of these
A(n) __________ is used as an index to pinpoint a specific element within an array. a. boolean value c. argument b. element d. subscript
d. subscript
The "has a" relationship is sometimes called a(n) __________ because one object is part of a greater whole. a. enterprise c. mutual relationship b. possession d. whole-part relationship
d. whole-part relationship
A partially filled array is normally used __________. a. when only a very small number of values need to be stored b. when you know how many elements will be in the array but not what the values are c. with an accompanying parallel array d. with an accompanying integer value that holds the number of items stored in the array
d. with an accompanying integer value that holds the number of items stored in the array
When an exception is thrown:
it must be handled by the program or by the default exception handler.
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?
the code
Instance methods should be declared static. True or False?
False
A method that gets a value from a class's field but does not change it is known as a mutator method. True or False?
False
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order. True or False
False
A sorting algorithm is used to locate a specific item in a larger collection of data. True or False?
False
All methods in an abstract class must also be declared abstract. True or False?
False
A class is not an object. It is a description of an object. True or False?
True
A class's static methods do not operate on the fields that belong to any instance of the class. True or False
True
A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final. True or False?
True
A constructer is automatically called when an object is created. True or False?
True
A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables. True or False?
True
An ArrayList object automatically expands in size to accommodate the items stored in it. True or False?
True
An abstract class is not instantiated itself but serves as a superclass for other classes. True or False
True
An access specifier indicates how the class may be accessed. True or False?
True
Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method. True or False?
True
Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members. True or False?
True
If object1 and object2 are objects of the same class, to make object2 a copy of object1 __________. a. write a method for the class that will make a field by field copy of object1 data members into object2 data members b. use the copy method that is a part of the Java language c. use the default constructor to create object2 with object1 data members d. use an assignment statement to make object2 a copy of object1
a. write a method for the class that will make a field by field copy of object1 data members into object2 data members
Which of the following is a correct method header for receiving a two-dimensional array as an argument? a. public static void passArray(int[1,2]) b. public static void passArray(int [][]) c. public static void passArray(int[1],[2]) d. public static void passArray(int[], int[])
b. public static void passArray(int [][])
Each of the numeric wrapper classes has a static ________ method that converts a number to a string. a. GetString b. Parse c. ToString d. Convert
c. ToString
If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts? a. numAccounts = account20.numAccounts; b. numAccounts = numOfAccounts; c. numAccounts = SavingsAccount.numberOfAccounts; d. numAccounts = account20;
c. numAccounts = SavingsAccount.numberOfAccounts;
When a field is declared static there will be __________. when a a. a copy of the field for each method in the class b. a copy of the field in each class object c. only one copy of the field in memory d. two reference copies of the field for each method in the class
c. only one copy of the field in memory
If a subclass constructor does not explicitly call a superclass constructor, __________. a. the superclass's fields will be set to the default values for their data types b. Java will automatically call the superclass's default or no-arg constructor immediately after the code in the subclass's constructor executes c. it must include the code necessary to initialize the superclass fields d. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes
d. Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes
In the following code, which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 } a. Line 1 b. Line 2 c. Line 3 d. Line 4
d. Line 4
Which of the following import statements is required to use the Character wrapper class? a. import java.String; b. import java.lang.Char; c. import java.Char; d. No import statement is required
d. No import statement is required
Two or more methods in a class may have the same name as long as __________.
they have different parameter lists
Which symbol indicates that a member is private in a UML diagram?
-
When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object. True or False?
False
An array can hold multiple values of several different types of data simultaneously. True or False?
False
If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector. True or False?
False
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned. True or False?
False
If a string has more than one character used as a delimiter, you must write a loop to determine the tokens, one for each delimiter character. True or False
False
If a[] and b[] are two integer arrays, the expression a == b compares the array contents. True or False?
False
A constructor is a method that:
Performs initialization or setup operations.
What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } a. A runtime error will occur. b. All the values in the array will be initialized to 10.0. c. All the values in the array except the first will be set to 10.0. d. The code contains a syntax error and will not compile.
a. A runtime error will occur.
What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. An array of 6 values, all initialized to 0 and referenced by the variable x will be created. b. An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. c. The variable x will contain the values 0 through 5. d. A compiler error will occur.
a. An array of 6 values, all initialized to 0 and referenced by the variable x will be created.
Which of the following is not true about static methods? a. It is not necessary for an instance of the class to be created to execute a static method. is not b. They are called by placing the key word static after the access specifier in the method header. c. They are called from an instance of the class. d. They are often used to create utility classes that perform operations on data but have no need to collect and store data.
a. It is not necessary for an instance of the class to be created to execute a static method. is not
Which of the following statements will convert the double variable, d = 543.98 to a string? a. String str = Double.toString(d); b. String str = double.toString(d); c. String str = double(d); d. String str = d.Double.toString(str);
a. String str = Double.toString(d);
Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str? a. String str = Integer.toString(number); b. String str = number.Integer.toString(str); c. String str = integer(number); d. String str = integer.toString(number);
a. String str = Integer.toString(number);
Which of the following statements will display the maximum value that a double can hold? a. System.out.println(Double.MAX_VALUE); b. System.out.println(Double.MAXIMUM_VALUE); c. System.out.println(Double.MAX_VAL); d. System.out.println(<double>(MAX_VALUE));
a. System.out.println(Double.MAX_VALUE);
What is required for an interface method that has a body? a. The method header must begin with the key word default. b. A class that implements the interface must override the method. c. The @Default annotation must precede the method header. d. All of these are true.
a. The method header must begin with the key word default.
When using the String class's trim method, a __________ cannot be trimmed. a. space b. tab c. semicolon d. newline
a. space
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; } a. The y field is available to code written outside the Circle class. b. The radius field is not available to code written outside the Circle class. c. The radius, x, and y fields are members of the Circle class. d. The x field is available to code that is written outside the Circle class.
a. The y field is available to code written outside the Circle class.
What will be displayed after the following code is executed? String str = "RSTUVWXYZ"; System.out.println(str.charAt(5)); a. W b. X c. V d. U
a. W
Given the following method header, what will be returned from the method? public Rectangle getRectangle() a. the address of an object of the Rectangle class b. the values stored in the data members of the Rectangle object c. a graph of a rectangle d. an object of the class Rectangle
a. the address of an object of the Rectangle class
In order to do a binary search on an array __________. a. the array must first be sorted b. you must first do a sequential search to be sure the element you are looking for is there c. the values of the array must be numeric d. no requirements are necessary
a. the array must be sorted
Which of the following is not true about static methods? a. They are created by placing the key word static after the access specifier in the method header. b. It is necessary for an instance of the class to be created to execute the method. c. They are called directly from the class. d. They are often used to create utility classes that perform operations on data but have no need to store and collect data.
b. It is necessary for an instance of the class to be created to execute the method.
Which of the following is true about protected access? a. Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. b. Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. c. Protected members cannot be accessed by methods in any other classes. d. Protected members are actually named constants.
b. Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package.
If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method? a. account20.getNumberOfAccounts(); b. SavingsAccount.getNumberOfAccounts(); c. getNumberOfAccounts(); d. iSavingsAccount.account20.getNumberOfAccounts();
b. SavingsAccount.getNumberOfAccounts();
What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb); a. The cow jumped over the moon. b. The cow jumped over the moon. c. The cow jump d. 12The cow jumped over the moon.
b. The cow jumped over the moon.
A deep copy of an object __________. a. is an assignment of that object to another object b. is an operation that copies an aggregate object and all the objects that it references c. is a bogus term and means nothing d. is always a private method
b. is an operation that copies an aggregate object and all the objects that it references
What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2); a. n fox b. jumped c. lazy d d. x jump
b. jumped?
Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement. a. str.uppercase(); b. str[0].upperCase(); c. str.toUpperCase(); d .str[0].toUpperCase();
b. str[0].upperCase();
CRC stands for __________. cd a. Class, Recyclability, Collaborations b. Class, Redundancy, Collections c. Class,Responsibilities, Collaborations d. Code, Reuse, Constancy
c. Class,Responsibilities, Collaborations
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC a. ClassA c. ClassC b. ClassB d. all are interfaces
c. ClassC
The JVM periodically performs the __________ process to remove unreferenced objects from memory. a. memory shuffling c. garbage collection b. system restore d. memory sweeping
c. Garbage collection
Which of the following is an example of a lambda expression? a. int x = x * factor; b. IntCalculator = new divider(x, 2); c. IntCalculator multiplier = x -> x * factor; d. Any of these are examples of a lambda expression.
c. IntCalculator multiplier = x -> x * factor;
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>(); a. It specifies that String objects may not be stored in the ArrayList object. b. It specifies that everything stored in the ArrayList object will be converted to a String object. c. It specifies that only String objects may be stored in the ArrayList object. d. It specifies that the ArrayList will be converted to a String array.
c. It specifies that only String objects may be stored in the ArrayList object.
In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement "+ "in the constructor."); } } a. This cannot be determined from the code. b. It will call the method super and pass the value 40 to it as an argument. c. It will call the constructor of ClassA that receives an integer as an argument. d. The method super will have to be defined before we can say what will happen.
c. It will call the constructor of ClassA that receives an integer as an argument.
Which of the following statements will print the maximum value an int variable may have? a. System.out.println(MAX_VALUE); b. System.out.println(integer.MAX_VALUE); c. System.out.println(Integer.MAX_VALUE); d. System.out.println(INTEGER.MAX_VALUE);
c. System.out.println(Integer.MAX_VALUE);
Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00); What is true about the following statement? System.out.println(account) a. A runtime error will occur. b. The method will display unreadable binary data on the screen. c. The account object's toString method will be implicitly called. d. A compiler error will occur.
c. The account object's toString method will be implicitly called.
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } } a. Nothing is wrong with this code. b. The method super is not defined. c. The call to the method super must be the first statement in the constructor. d. No values may be passed to super.
c. The call to the method super must be the first statement in the constructor.
What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; } a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the lowest value in the numbers array. d. The value variable will contain the highest value in the numbers array.
c. The value variable will contain the lowest value in the numbers array.
If the following is from the method section of a UML diagram, which of the statements below is true? + add(object2:Stock) : Stock a. This is a private method named add that accepts and returns objects of the Stock class. b. This is a private method named Stock that adds two objects. c. This is a public method named add that accepts and returns references to objects in the Stock class. d. This is a public method named Stock that adds two objects.
c. This is a public method named add that accepts and returns references to objects in the Stock class
Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant? a. enum.PINE c. Tree.PINE b. PINE d. enum.Tree.PINE
c. Tree.PINE
(ON EXAM) What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3); a. 56H b. 56h c. True-x d. false
c. True-x
The following statement is an example of __________. import java.util.*; a. an explicit import statement b. an unconditional import statement c. a wildcard import statement d. a conditional import statement
c. a wildcard import statement
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? a. set b. store c. add d. insert
c. add
To return an array of long values from a method, which return type should be used for the method?
c. long[]
To compare two objects in a class, __________. r a. use the == operator (for example, object1 == object2) b. write a method to do a byte-by-byte compare of the two objects c. write an equals method that will make a field by field compare of the two objects d. This cannot be done since objects consist of several fields.
c. write an equals method that will make a field by field compare of the two objects
A(n) __________ can be thought of as a blueprint that can be used to create a type of __________.
class; object
What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.lastIndexOf("ov", 14); a. 14 b. 1 c. 0 d. -1
d. -1
In Windows, which of the following statements will open the file, InputFile.txt, that is in the root directory on the C: drive?
d. FileReader freader = new FileReader("C:\\InputFile.txt");
What does the following statement do? double[] array1 = new double[10]; a. It declares array1 to be a reference to an array of double values. b. It will allow valid subscripts in the range of 0 through 9. c. It creates an instance of an array of ten double values. d. It does all of these.
d. It does all of these.
One or more objects may be created from a(n) __________. a. field b. method c. instance d. class
d. class
Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree? a. UML diagram c. flowchart b. CRC card d. class hierarchy
d. class hierarchy
38. If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array? a. for (int row = 1; row < numbers.length; row++) { for (int col = 1; col < numbers.length; col++) total += numbers[row][col]; } b. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } c. for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } d. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
d. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
Which of the following statements converts a String object variable named str to an int and stores the value in the variable x? a. int x = Integer.integer(str); b. int x - str; c. int x = Integer.parseInteger(str); d. int x = Integer.parseInt(str);
d. int x = Integer.parseInt(str);
Which of the following statements will convert the string, str = "285" to an int? a. int x = str; b. int x = Integer.parseInteger(str); c. int x = Integer.integer(str); d. int x = Integer.parseInt(str);
d. int x = Integer.parseInt(str);
The ArrayList class is in the __________ package. a. java.arraylist c. java.array b. java.lang d. java.util
d. java.util
Overloading means that multiple methods in the same class __________.
have the same name, but different parameter lists
If two methods in the same class have the same name but different signatures, the second overrides the first. True or False?
False
In an inheritance relationship, the subclass constructor always executes before the superclass constructor. True or False?
False
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class. True or False?
False
The public access specifier for a field indicates that the field may not be accessed by statements outside the class. True or False?
False
The term "default constructer" is applied to the first constructer written by the author of the class. True or False?
False
In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0); a. int b. char[] c. char d. String
b. char[]
What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true); a. 9, 14, 2018 c. - b. 9, 14, 2018, - d. None of these
a. 9, 14, 2018
A ragged array is __________. a. a two-dimensional array where the rows have different numbers of columns b. a one-dimensional array for which the number of elements is unknown c. a two-dimensional array for which the number of rows is unknown d. a partially initialized two-dimensional array of ranged values
a. a two-dimensional array where the rows have different numbers of columns
In memory, an array of String objects __________. a. consists of elements, each of which is a reference to a String object b. is compressed to four bytes for each element c. must be initialized when the array is declared d. consists of an array of references to String objects
a. a. consists of elements, each of which is a reference to a String object
Which of the following is a correct method header for receiving a two-dimensional array as an argument? a. public static void passMyArray(int[1, 2]) b. public static void passMyArray(int[][]) c. public static void passMyArray[1][2]) d. public static void passMyArray(int[],int[] myArray)
b. public static void passMyArray(int[][])
37. Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"}; a. for (int i = 0; i < names.length; i++) System.out.println(names[i].length); b. for (int i = 0; i < names.length(); i++) System.out.println(names[i].length); c. for (int i = 0; i < names.length; i++) System.out.println(names[i].length()); d. for (int i = 0; i < names.length(); i++) System.out.println(names[i].length());
c. for (int i = 0; i < names.length; i++) System.out.println(names[i].length());
A constructor ____________ a. always accepts two arguments b. has the return type of void c. has the same name as the class d. always has a private access specifier
c. has the same name as the class
Which of the following is a valid declaration for a ragged array with five rows but no columns? a. int[][] ragged = new int[5]; b. int[][] ragged = new int[][5]; c. int[][] ragged = new int[5][]; d. int[] ragged = new int[5];
c. int[][] ragged = new int[5][];
A search algorithm __________. a. arranges elements in ascending order b. arranges elements in descending order c. is used to locate a specific item in a collection of data d. is rarely used with arrays
c. is used to locate a specific item in a collection of data
Each array in Java has a public field named __________ that contains the number of elements in the array.. a. size b. capacity c. length d. limit
c. length