Java Chapters 6-10
Which key word indicates that a class inherits from another class
extends
If str is declared as : String str = "ABCDEFGHI" ; What will be returned from the following statement? Character.toLowerCase (str.charAt ( 5 ) )
f
When a method's return type is a class, what is actually returned to the calling program?
A reference to an object of that class
Which of the following ArrayList class methods is sued to insert an item at a specific location in an ArrayList?
Add
What is required for am interface method that has a body?
The method header must begin with the key word default
A class is not an object. It is a description of an object
True
An object can store data
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
Declaring an array reference variable does not create an array
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
The java.lang package is automatically imported imported into all Java programs
True
When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object
True
You cannot use the fully-qualified name of an enum constant for
a case expression
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
To indicate the data type of a variable in a UML diagram, you enter
a variable name followed by a colon and the data type
When a subclass overloads a superclass method
Both methods may be called with a subclass object
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
ClassA
Given the following code, which statement is TRUE public class ClassB implements ClassA { }
ClassB must override each method in ClassA
A sorting algorithm is used to locate a specific item in a larger collection or data
False
All methods in an abstract class must also be declared abstract
False
An array can hold multiple values of several different types of data simultaneously
False
Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class
False
The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value
False
The public access specifier for a field indicates that the field may not be accessed by statements outside the class
False
Which of the following statements will display the maximum value that a double can hold?
System.out.println ( Double . MAX_VALUE ) ;
It is common practice in object-oriented programming to make all of a class's
field's private
Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?
int x = Integer . parseInt ( str ) ;
Which of the following statements will convert the string, str = "285" to an int?
int x = Integer.parseInt ( str );
A deep copy of an object
is an operation that copies an aggregate object object and all the objects that it references
The ______ package is automatically imported into all Java programs
java.lang
Enumerated types have the __________ methods which returns the position of an enum constant in the declaration list
ordinal
A constructor is a method that
performs initialization or setup operations
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
polymorphic
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passMyArray (int [ ] [ ] )
The __________ key word is used to call a superclass constructor explicitly
super
In order to do a binary search on an array
the array must first be sorted
The scope of a public instance field is
the instance methods and methods outside outside the class
Which symbol indicates that a member is public in a UML diagram
+
By default, Java initializes array elements to
0
Java automatically stores a _________ value in all uninitialized static member variables
0
Subscript always starts with
0
What are the tokens in the following code? String str = "123-456-7890"; String [ ] tokens = str.split ("-");
123, 456, 7890
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 ; }
60
StringTokenizer st = new StringTokenizer ("9-14-2018", "-", true);
9, 14, 2018, -
What does the following UML diagram entry mean ? + setHeight (h : double) : void
A public method with a parameter of a data type double that does not return a value
A ragged array is
A two-dimensional array where the rows have different numbers of columns
The following statement is an example of import java.util.*;
A wildcard import statement
A UML diagram does not contain
The object names
When an object is passed as an argument, it is actually a reference to the object that is passed
True
After the header, the body of the method appears inside of a set of
braces, { }
In the following statement, what data type must recField be? str.getChars ( 5, 10, recField, 0 ) ;
char [ ]
What type of relationship exists between two objects when one object is a specialized version of another object?
" is a "
__________ is the term for the relationship created by aggregation
"Has a"
The whole-part relationship created by object aggregation is more often called a(n) _____________ relationship
"has a"
What would be the result of executing the following code? int [ ] x = { 0 , 1, 2, 3, 4, 5 } ;
An array of 6 values, ranging from 0 to 5 and referenced by the variable x will be created
The following statement is an example of
An explicit import statement
_____________ refers to combining data and code into a single object
Encapsulation
In an inheritance relationship, the subclass constructor always executes before the superclass constructor
False
Java limits the number of dimensions that an array can have to 15
False
The key word this is the name of a reference variable that is available to all static methods
False
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable
False
You can declare an enumerated data type inside a method
False
It is common practice to use a __________ variable as a size declarator
Final
The JVM periodically performs the _________ process to remove unreferenced objects from memory
Garbage colloection
Another term for an object of a class is a(n)
Instance
Which of the following import statements is required to use the Character wrapper class
No import statement required
You cannot use the == operator to compare the contents of
Objects
When you work with a _________, you are using a storage location that holds a piece of data
Primitive variable
When declaring class data members it is best to declare them as
Private members
You can use the _________ method to replace an item at a specific location in an ArrayList
Set
In a class hierarchy
The more general classes are toward the top of the tree and the more specialized classes are toward the bottom
Given the following two-dimensional array declaration, which statement is true? int [ ] [ ] numbers = new int [ 6 ] [ 9 ] ;
The numbers array has 6 rows and 9 columns
If you attempt to perform an operation with a null reference variable
The program will terminate
In an inheritance relationship
The superclass constructor always executes before the subclass constructor
A functional interface is simply an interface that has one abstract method
True
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 a mutator method
True
If a non-letter is passed to the toLowerCase to or the toUpperCase method, it is returned unchanged
True
The String [ ] args parameter in the main method header allows the program to receive arguments from the operating system command-line
True
Trying to extract more tokens than exist from a StringTokenizer object will cause an error
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, productCodes [ 1 ], 2, 3);
True
enum constants have a toString method
True
What will be displayed after the following code is executed? String str = ""RSTUVWXYZ" ; System.out.println ( str.charAT ( 5 ) ) ;
W
The binary search algorithm
Will cut the portion of the array being searched in half each time it fails to locate the search value
A class becomes abstract when you place the __________ key word in the class definition
abstract
A(n) __________ method is a method that appears in a superclass but expects to be overridden in a subclass
abstract
A class that is defined inside another is called a(n)
inner class
A __________ member's access is somewhere between public and private
protected
All methods specified by an interface are
public
Which of the following statements correctly specifies two interfaces
public class ClassA implements Interface1, Interface2
The __________ method removes an item from an ArrayList
remove
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
str [ 0 ] . toUpperCase ( ) ;
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") ;
str would reference "Little Jack Horner sat on the corner".
The term __________ is commonly used to refer to a string that is part of another string
substring
A series of words or other items of data, separated by spaces or other character, is known as a
token
The process of breaking a string down into tokens is known as
tokenizing
The __________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted
trim
The process of converting a wrapper class object to a primitive type is known as
unboxing
The sequential search algorithm
uses a loop to sequentially step through an array, starting with the first element
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 fields
Given the following, which of the statements below is NOT true? str.insert ( 8, 32 );
The insert will start at position 32
Which of the following for loops is valid, given the following declaration? String [ ] name = { "abc", "def", "ghi", "jkl" } ;
for ( int i = 0; i < names.length; i ++ ) System.out.println (names [ i ] . length ( ) ) ;
What of the following is an example of a lamda expression?
int x = x * factor ;
Instance methods should be declared static
False
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);
The cow jumped over the moon.
The ____________character appears at the end ( the right side ) of a string, after the non-space character
Trailing whitespaces
Gicven the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant ?
Tree.PINE
A wrapper class is a class that is "wrapper around" a primitive data type and allow you to create objects instead of variables
True
An ArrayList object automatically expands in size to accommodate to the items stored in it
True
An abstract class is not instantiated itself but serves as a superclass for other classes
True
An access specifier indicates how a class may be accessed
True
An enumerated data type is actually a special type of class
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
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
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
Objects in an array are accessed with subscripts, just like any other data type in an array
True
Once and array is created, its size cannot be changed
True
The wrapper classes in Java are immutable, which means that once you create an object, you cannot change the object's value
True
When an array of objects is declared but not initialized, the array value are set to null
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
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
For the following code, what would be the value of str [ 2 ]?
a reference to the String object containing "ghi"
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC
ClassC
If a [ ] and b [ ] are two integer arrays, the expression a == b compares the array contents
False
If a non-letter argument us passed to the toLowerCase or toUpperCase method, the boolean value false is returned
False
The names of the enum constants in an enumerated data type must be enclosed in quotation marks
False
A class specifies the __________ and __________ that a particular type of object has
fields, methods
When a method is declared with the __________ modifier, it cannot be overridden in a subclass
final
If a method in a subclass has the same signature as a method method in a superclass, the subclass method __________ the superclass method
overrides
Which of the following statements declares Salaried as a subclass of PayType?
public class Salaried extends PayType
When using the String class's trim method, a ___________ cannot be trimmed
semicolon
The ___________ method of the String class can be used to tokenize a string
split
Static methods can only operate on ______ fields
static
When an individual element of an array is passed to a method
the method does not have access to the original array
When an object is passed as an argument to a method, what is passed into the method's parameter variable
the object's memory address
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 ]; }
The value variable will contain the lowest value in the numbers array
A class's static methods methods do not operate on the fields that belong to any instance of the class
True
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable
True
StringBuilder objects are not immutable
True
When an object reference is passed to a method, the method may change the values of the object
True
You can change the contents of a StringBuilder object, but you cannot change the contents of a String object
True
What will be the results after the following code is executed? int [ ] array1 = new int [25] ; ...// Code that will put value in array1 int value = array1 [ 0 ] ; for ( int a = 1; a < array1.length ; a ++ ) { if ( array1 [ a ] < value ) value = array1 [ a ]; }
Value contains the lowest value in array1
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 ) ;
9
What is the value of the 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} } ;
94
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
Array bounds checking
If a subclass constructor does not explicitly call a superclass constructor
Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes
Autoboxing is
Java's process of automatically "boxing up" a value inside an object
Each array in Java has a public field named___________ that contains the number of elements in the array
Length
Replacing inadequate superclass methods with more suitable subclass methods is known as
Method Overriding
Class objects normally have ________ that perform useful operations on their data, but primitive variable do not
Methods
Which of the following NOT true about static methods?
They are called from an instance of a class
The only limitation that static methods have is
They cannot refer to nonstatic members of the class
Two or more methods in a class may have the same name as long as
They have different parameter lists
final int SIZE = 25 ; int [ ] array1 = new int [ SIZE ] ; ... // Code that will put values on array1 int value = 0 ; for ( int a = 0 ; a <= array1.length ; a ++ ) { value += array1 [ a ] ; }
This code would cause the program to crash
Each of the numeric wrapper classes has a static ________ method that converts a number to a string
ToString
Any __________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is
nonletter
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
Protected class members can be denoted in a UML diagram with the _________ symbol
#
The String class's regionMatches method performs a case-sensitive comparison
True
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 [ ] ?
0 through 14
Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the ordinal value of the MAPLE enum constant?
1
When an array is passed to a method
1) It is passed just as any other object would be passed 2) The method has direct access to the original array 3) A reference to the array is passed
A class's responsibilities include
1) the things a class is responsible for knowing 2) the things a class is responsible for doing
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold ______________ characters
16
If a subclass constructor does not explicitly call a superclass
Java will automatically call the superclass's default or no arg-constructor just before the code in the subclass's constructor executes
An object's __________ is simply the data that is stored in the object's fields at any given moment
State
Which of the following statements will print the maximum value an int variable may have?
System.out.println ( Integer.MAX_VALUE );
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?
numAccounts = SavingsAccount . numberOfAccounts;
A subclass may call an overridden superclass method by
prefixing its name with the super key word and a dot ( . )
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passArray ( int [ ] [ ] )
The term ___________ commonly is used to refer to a string that is part of another string
substring
The Character wrapper class provides numerous methods for
testing and converting character data
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application
the code
The scope if a private instance field is
the instance methods of the same class
When a reference variable is passed as an argument to a method
the method has access to the object that the variable references
The String class's __________ method accepts a value of any primitive data type as its argument and returns a string representation of the value
valueOf
The "has a" relationship is sometimes called a(n) _________ because one object is a part of a greater whole
whole-part relationship
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
wrapper class
To compare two objects in a class,
write an equals method that will make a field by field compare of the two objects
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 ;
x [ ] = { 36, 78, 12, 24 } and y [ ] = { 36, 78, 12, 24 }
A partially filled array is normally used
With an accompanying integer value that holds the number of items stored in the array
If object1 and object2 are objects of the same class, to make object2 a copy of object1
Write a method for the class that will make a field by field copy of object1 data members into object2 data members
When you make a copy of the aggregate object and of the objects that it references
You are performing a shallow copy
What will be displayed after the following cade is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring (20, 26) ; System.out.println(str2);
jumped
__________ is a special type of expression used to create an object that implements a functional interface
lambda
To return an array of long values from a method, which return type should be used for the method?
long [ ]
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
Instance methods do not have the key word static in their headers
True
It is not possible for a superclass to call a subclass's method
True
Java does not limit the number of dimensions an array may have
True
Most of the String comparison methods are case sensitive
True
The key word this is the name of a reference variable that an object can use to refer to itself
True
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
True
To determine if two arrays are equal you must compare each of the elements of the two arrays
True
When a subclass extends a superclass, the public members of the superclass become public members of the subclass
True
You can write a super statement that calls a superclass constructor but only in the subclass's constructor
True
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 ] ; }
Value contains the sum of all the values in array1
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 ] ; }
x [ ] = { 36, 78, 12, 24 } and y [ ] = { 36, 78, 12, 24 }
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
You cannot assign a value to a wrapper class object
False
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 ) ;
7
__________ tells the Java compiler that a method is meant to override a method in he superclass
@Override
In __________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass
A UML diagram
If ClassC is derived from ClassB which is derived from ClassA, this would be an example of
A chain of inheritance
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 runtime error will occur
The _________ indicates the number of elements the array can hold
Array's size declarator
If the following is from the method section of a UML diagram, which of the statements below is true? + add ( object2 : Stock ) : Stock
This is a public method named add that accepts and returns references to objects in the Stock class
If the following is from the method section of the UML diagram, which of the statements below is true? + equals ( object2 : Stock ) : boolean
This is a public method that accepts a Stock object as its argument and returns a boolean value
A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final
True
A constructor is a method that is automatically called when an object is created
True
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 = 5
The _______ method is used to insert an item into an ArrayList
add
A static field is created by placing the key word static
after the access specifier and before the field's data type
When an "is a" relationship existed between objects, the specialized object has
all of the characteristics of the general object plus additional characteristics
All fields declared in an interface
are treated as final and static
One or more objects may be created from a(n)
class
A(n) ____________ can be thought of as a blueprint that can be used to create a type of
class, object
You can concatenate String objects by using the
concat method or the + operator
In memory, an array of String objects
consists of elements, each of which is a reference to a String object
The term used for the character that separates tokens is
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 fidde " ; str = sourceStr.substring (12,17);
diddl
Which of the following statements will convert the string, str = "285.74" to a double?
double x = Double.parseDouble (str);
Which symbol indicates that a member is private in a UML diagram
-
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) ;
-1
What does the following statement do? double [ ] array1 = new double [ 10 ] ;
1 ) It declares array1 to be a reference to an array of double values 2 ) It will allow valid subscripts in the range of 0 through 9 3 ) It creates an instance of an array of ten double values
In Java it is possible to write a method that will return
1 ) a whole number 2 ) a reference to an object 3 ) a string of characters ANY OF THESE
The StringBuilder class's insert method allows you to insert a(n) ____________ into calling object's string
1 ) char array 2 ) primitive type 3 )String object ALL OF THESE
If a class contains an abstract method
1 ) you must created an instance of the class 2 ) The method will only have a header, but not a body, and will end with a semicolon 3 ) the method cannot be overridden in subclasses ALL OF THESE ARE TRUE
A protected member of a class may be directly accessed by
1) methods of the same class 2) methods of a subclass 3) methods in the same package ANY OF THESE
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") ;
15
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 ; }
180
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 ) ) }
456
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 ++ ; }
ABC
The __________ class is the wrapper class for the char for the char data type
Character
Which of the following shows the inheritance relationships among classes in a manner similat to that of a family tree
Class hierarchy
CRC stands for
Class, Responsibilities, Collaborations
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
ClassB
A method that gets a value from a class's field but does not change it is known as a mutator method
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 destroyed by the garbage collector
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
False
If two methods in the same class have the same name but different signatures, the second overrides the first
False
The following statement correctly creates a StringBuilder object StringBuilder str = "Tuna sandwich" ;
False
The term "default constructor" is applied to the first constructor written by the author of the class
False
You should not define a class that is dependent on the values of other class field
In order to avoid having stale data
In Java, you do not use the new operator when you use a(n)
Initialization list
Methods that operate on an object's fields are called
Instance Methods
Then an object is created, the attributes associated with the objects are called
Instance fields
A search algorithm
Is used to locate a specific item in a collection of data
Which of the following is NOT true about static methods
It is necessary for an instance of the class to be created to execute the method
When the this variable is used to call a constructor
It must be the first statement in the constructor making the call
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String> ( ) ;
It specifies that only String objects may be stored in the ArrayList object
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 ) ;
The account object's toString method will be implicitly called
Given the following method header, what will be returned from the method? public Rectangle getRectangle ( )
The address of an object of the Rectangle class
Which of the following is true about protected access?
Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package
If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method?
SavingsAccount . getNumberOfAccounts ( ) ;
Instance methods do not have _______ key word in their headers
Static
Java allows you to create objects of the ___________ class in the same way that you would create primitive variables
String
Which of the following statements will create a reference, str, to the String "Hello, World"?
String str = "Hello, World";
Which of the following statements will convert the double variable, d = 543.98 to a string?
String str = Double.toString ( d );
Which of the following statements converts an int variable names number to a string and stores the value in the String object variable named str?
String str = Integer . toString ( number );
A(n) _________ is used as an index to pinpoint a specific element within an array
Subscript
What would be the result after the following code is executed? int [ ] numbers = { 50, 10, 15, 20, 25, 100, 30 } ; int value = 0 ; for ( int i = 1 ; i < numbers . length ; i ++ ) value += numbers [ i ] ;
The value variable will contain the sum of all the values in the numbers array
For the following code, which statement is NOT true? public class Circle { private double radius; public double x; private double y; }
The y field is available to code written outside the Circle class
For the following code, which statement is NOT true? public class Sphere { private double radius; public double x; private double y; private double z; }
The z field is available to code written outside the Sphere class
A single copy of a class's static field is shared by all instances of the class
True
A sorting algorithm is a technique for scanning through an array and rearranging its content in some specific order
True
Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members
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
Every class has a toString method that an equals method inherited from the object class
True
A reference variable stores a(n)
memory address
a declaration for an enumerated type begins with the __________ key word
enum
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?
for ( int row = 0; row < numbers.length; row ++ ) { for ( int col = 0; col < number [ row ] . length; col ++ ) total += numbers [ row ] [ col ] ;
A constructor
has the same name as the class
Overloading means that multiple methods in the same class
have the same name but different parameter lists
Methods that operate on an object's fields are called
instance methods
Which of the following is the operator used to determine whether an object is an instance of a particular class?
instanceOf
Which of the following is a valid declaration for a ragged array with five rows but no columns?
int [ ] [ ] ragged = new int [ 5 ] [ ] ;
The ArrayList class is in the __________ package
java.util
What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the mood."; String str2 = "moon"; matches = str1.endsWith (str1 ) ; System.out.println (matches);
moon
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?
numbers [ r ] . length
Most od the programming languages used today are
object-oriented
When a field is declared static there will be
only one copy of the field in memory
A subclass can directly access?
only public and protected members of the superclass
If two methods have the same name but different signatures they are
overloaded
A group of related classes is called a(n)
package
If you don't provide an access specifier for a class member, the class member is given __________ access by default
package