Java Ch 8 - 11
SavingsAccount.getNumberOfAccounts();
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?
integer x = Integer.parseInt(str);
To convert the string, str = "285" to an integer and store it in the variable x, use the following statement
double x = Double.parseDouble(str);
To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement.
Write a copy method that will make a field by field copy of the two objects
To copy an object to another object of the same class
No import statement is needed
Use the following import statement when using the character wrapper class
An array of 6 values ranging from 0-5 and referenced by the variable x will be created
What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};
123, 456 7890, and -
What will be the tokens in the following statement? StringTokenizer = strToken new StringTokenizer("123-456-7890", "-",true);
15
What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon." loc = str.indexOf("ov");
-1
What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon." loc = str.lastIndexOf("ov",14);
True
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, productCode[1], 2, 3)
public class Salaried extends PayType
Which of the following statements declares as a subclass of PayType?
a case expression
You cannot use the fully-qualifed name of an enum constant for this
A case experssion
You cannot use the fully-qualified name of an enum constant for this
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.
With a line that has an open arrowhead at one end that point to the base class
In UML diagrams, inheritance is shown
1
Look at the Following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant?
Tree.PINE
Look at the following declaration. enum Tree { OAK, MAPLE, PINE } What is the fully-qualified name of the PINE enum constant?
Will cut the portion of the array being searched in half each time the loop fails to locate the search value
The binary search algorithm
Protected members may be accessed by methods in the same package or in a derived class, even when the derived class is in a different package
The difference between protected access and package is
**It specifies that only String objects may be stored in the ArrayList object.
The following statement creates an ArrayListobject. What is the purpose of the notation? ArrayList<String> arr = new ArrayList<String>();
Write an equals method that will make a field by field comparison of the two object
To compare two objects
String str = Double.toString(d);
To convert the double variable, d = 543.98, to a string, use the following statement,
String str = Integer.toString(number);
To convert the integer vaiable, number = 56, to a string, use the following statement
diddl
What is the value of str after the followuing code has been executed? String str; Strinf sourceStr = 'Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);
456
What will be printed after the after the following code is executed? String str = "abc456"; int i = 0; while (1<6) { if(!Character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i++; }
ABC
What will be printed after the after the following code is executed? String str = "abc456"; int i = 0; while (1<6) { if(character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i++; }
The address of an object in the class Rectangle
What will be returned from a method, if the following is the method header: public Rectangle getRectangle()
180
What will be the value of x[8] after the following code has been 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; }
60
What will be the value of x[8] after the following code has been 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; }
"is a"
When on object is a specialized version of another object, there is a(n) ____ relationship between them.
Another StringBuffer type
When using StringBuffer insert method, you cannot insert
trim
When you are writing with string objects that may have unwanted spaces at the beginning or end of the strings, use the ____ method to delete them.
public class ClassA implements Interface1, Interface2, Interface3
Which of the following statements correctly specifies three interfaces:
The equals and compareTo methods that automatically come with the enum data type
You may use this to compare two enum data values.
False
You must call a method to get the value of a wrapper class object
True
A class's static methods do not operate on the fields that belong to any instance of the class
Only Public and protected members of the base class
A derived class can directly access
Methods of the same class; Methods of a Subclass; Methods in the Same Package
A protected member of a class may be directly accessed by
A two-dimensional array when the rows are of different lengths
A ragged array is
Are final and static
All fields declared in an interface
False
All methods in an abstract class must also be declared abstract
They provide static methods that are very useful
Although it is not normally useful to create objects from the wrapper classes, programmers might use wrapper classes because
True
An ArrayList object automatically expands in size to accommodate the items stored in it.
True
An abstract class is not instantiated, but serves as a superclass for other classes.
True
An instance of a class does not have to exist in order for values to be stored in a class's static fields
Has a
The term for the relationship created by object aggregation is
All of the above
What does the following statement do? double[] array1 = new double[10];
We have lived in Tampa, Trenton, and Atlanta.
What will be the value of strbuff after the following statements are executed? StringBuffer strbuff = new StringBuffer('We have lived in Chicago, Trenton, and Atlanta." strbuff.replace(17,24,"Tampa");
We have lived in Chicago, Tampa, and Atlanta.
What will be the value of strbuff after the following statements are executed? StringBuffer strbuff = new StringBuffer('We have lived in Chicago, Trenton, and Atlanta." strbuff.replace(26,33,"Tampa");
38
What will be the value of x[1] after the following code is executed? int[] x = { 22, 33, 44 }; arrayProcess(x); ... public static void arrayProcess(int[] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the results after the following code was 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 = 5
What would be the results of the following code? 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 reference to an object of that class
When a method's return type is a class, what is actually returned to the calling program?
All the characteristics of the general object, plus additional chracteristics
When an "is a" relationship exists between objects, it means that the specialized object has
True
When an Object is passed to a method, the method may change the values in the object
False
When an interface variable references an object you can use the interface variable to call all the methods in the class implementing the interface.
Private Members
When declaring class data members, it is best to declare them as
System.out.println(Integer.MAX_VALUE);
Which of the following Statements will print the maximum value an integer variable may have?
They are called from an instance of the class.
Which of the following is not true about static methods?
False
You can declare an enumerated data type inside of a method.
add
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.
The insert will start at position 32
Given the following statement, which of the following is not true? str.insert(8,32)
The array numbers has 6 rows and 9 columns
Given the following two-dimensional array declaration, which statement is true? int [][] numbers = new int [6] [9];
Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
If ClassA is Derived from ClassB, then
The method will have only a header, but not a body, and end with a semicolon
If a class contains an abstract method,
True
If a non-letter is passed to toLowerCase or toUpperCase method, it is returned unchanged
False
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one fore each delimiter character.
This is a public method that accepts a FeetInches object as its argument and returns a boolean value
If the following is from the method section of a UML diagram, which of the following statements is true? + equals(object2:Stock) : boolean
True
If you are using characters other than whitespaces as delimeters, 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
Package
If you do not provide an access specifier for a class member, the class member is given ___ access by default
The more general classes are toward the top of the tree and the more specialized are toward the bottom
In a class hierachy
Token
In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the data items is
False
In an inheritance relationship, the derived class constructor always executes before the base class constructor
Public access
In an interface all methods have
Consists of an array of references to Stringobjects
In memory, an array of String objects
True
It is not possible for a super class to call a subclass's method.
False
StringBuffer objects are immutable.
True
StringBuffer objects are not immutable.
Testing and converting char variables
The Character wrapper provides numerous methods for
garbage collection
The JVM periodically performs this process to remove unreferenced objects from memory.
16 characters
The parameterless constructor for a StringBuffer object gives the object enough storage space to hold ___
. It must be the first statement in the constructor making the call
When the this variable is used to call a constructor,
System.out println(Double.MAX_VALUE);
which of the following statements will print the maximum value a double variable may have?
ordinal
Enumerated types have this method, which returns the position of an enum constant in the declaration list.
True
Every class has a toString method and equal's method inherited from the Object class
True
Every class is either directly or indirectly derived from he Object class.
numAccounts = SavingsAccount.numberOfAccounts;
If you have defined a class named SavingsAccountwith a public static data member namednumberOfAccounts, and created a SavingsAccountobject referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?
The array must first be sorted in ascending order
In order to do a binary search on an array,
ClassB
In the following statement which is the base class? public class ClassA extends ClassB implements ClassC
#
Protected class members are denoted in a UML diagram with the symbol
Not quite private; Not quite different
Protected members are
Give the object, str, 25 bytes of storage and not store anything in them
The following StringBuffer constructor will StringBuffer str = new String Buffer(25)
import java.util.StringTokenizer;
To use the class StringTokenizer, you must have the following import statement.
Use the concat() method or use the + between the two Strings
Two ways of concatenating two strings are
False
What eill be the value of matches after the following code has been executed> boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon'; matches = str1.endsWith(str2);
It Creates a Double Object; It initializes that object to 8.8; It assigns the object's address to the number variable
What does the following statement do? Double number = new Double(8.8);
It creates a Float Object; It initializes that object to 8.8; It assigns the object's address to the number variable
What does the following statement do? Float number = new Float(8.8);
set
You can use this ArrayList class method to replace an item at a specific location in anArrayList.
False
You cannot assign a value to a wrapper class object.
strbuff would equal "The cow jumped over the moon"
What would be the results of executing the following code? StringBuffer strbuff = new StringBuffer(12); strbuff.append("The cow"); strbuff.append("jumped over the"); strbuff.append("moon");
January, 1, 2004, space, comma
what will be the tokens in the following statements? StringTokenizer strToken = newStringTokenizer("January 1, 2003", ",",true);
True
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
They are immutable, They are not easy to use
Few programmers use wrapper classes because
They cannot refer to non-static members of the class
The only limitation that static methods have is
Uses a loop to sequentially step through an array, starting with the first element
The sequential search algorithm
False
The valueOf() method accepts a string representation as an argument and returns its equivalent integer value.
True
The valueOf() method accepts a value of any primitive data type as an argument and returns a string representation of the value.
remove
This ArrayList class method deletes an item from an ArrayList.
33
int[] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; }
A compiler error will result, if it is not the first statement of the constructor
If the this variable is used as a constructor call,
False
If two methods in the same class have the same name but different signatures, the second overrides the first.
Semicolon
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter?
9
For the following code, how many times would the loop execute? StringTokenizer strToken = new StringTokenizer("Cars, trucks, and SUVs are all types of automobiles."); while(strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); }
7
For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer('Ben and Jerry's ice cream is great.'); while (strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); }
A reference to the String "ghi"
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
str[0].toUpperCase();
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement
ClassB must override each method in ClassA
Given the following statement which of the following is true? public class ClassB implements ClassA{ }
A compiler error will result if it is not the first statement of the constructor
If the this variable is used as a constructor call,
A chain of inheritance
If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of
f
If String str = "ABCDEFGHI," what will be returned from Character.toLowerCase(str.charAt(5))?
W
If String str = "RSTUVWXYZ", what will be the value returned from str.charAt(5)?
Then a class that is derived from it, must call one of the constructors that the base class does have
If a base class does not have a default constructor,
You cannot create an instance of the class; The method will have only a header, but not a body, and end with a semicolon; Then Method must be overridden in subclasses
If a class contains an abstract method
False
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes
If a subclass constructor does not explicitly call as superclass constructor,
False
If a[] and b[] are two integer arrays, the expression a == b compares the array contents.
for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
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?
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());
With a line that has an open arrowhead at one end that points to the superclass
In UML diagrams, inheritance is shown
Delimiter
In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the spaces or other characters is
char[ ]
In the following statement, what data type must recField be: str.getChars(5, 10, recField, 0);
True
Java does not limit the number of dimensions that an array may have.
True
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;
str would equal " Little Jack Horner sat on the corner"
What would be the results of executing the following code? StringBuffer str = new String Bufffer("Little Jack Horner") str.append("sat on the"); str.append("corner");
value contains the sum of all the values in array1
What would be the results of the following code? 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]; }
Value contains the lowest value in array1
What would be the results of the following code? 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]; }