- •Import java.Util.*;
- •I, II, and III
- •I only
- •I, II, and III
- •I, II, and III
- •II only
- •III only
- •I and II only
- •II only
- •I and III only
- •I only
- •II and III only
- •I only
- •I and II only
- •I and III only
- •I, II, and III
- •II only
- •II only
- •I only
- •II only
- •II and III only
- •I and III only
- •I and II
- •I, II, and III
I, II, and III
II only
II and III only
I and III only
In Java, a(n) _____ is an instance of a(n) _____.
object, primitive type
class, primitive type
class, object
object, class
In Java, instance fields and methods of an object can be accessed with which of the following operators?
( )
new
[ ]
.
Consider the following Java program segment.
String s1 = new String("ABC");
String s2 = new String("ABC");
Boolean b1 = (s1 == s2);
s2 = new String("XYZ");
s1 = s2;
Boolean b2 = (s1 == s2);
At the end of execution of the segment, the value of b1 will be _____ and the value of b2 will be _____.
true, false
false, false
true, true
false, true
Consider the following Java program segment.
String s1 = new String("ABC");
String s2 = new String("ABC");
Boolean b1 = (s1 == s2);
Boolean b2 = s1.equals(s2);
At the end of execution of the segment, the value of b1 will be _____ and the value of b2 will be _____.
true, false
false, false
true, true
false, true
When comparing for equality in Java, primitives are compared with the operator _____, and objects are compared with the operator _____.
.equals, ==
==, =
=, ==
==, .equals
In Java, which of the following modifiers indicates that a field cannot be accessed from outside its class?
static
final
public
private
Consider the following Java program segment.
public class Foo {
public static int x;
}
If two separate Foo objects are instantiated, x is created in memory _____ time(s) because it is a _____ variable.
one, instance
two, class
two, instance
one, class
In Java, class variables must be declared with which of the following modifiers?
class
final
public
static
Which of the following is (are) true of static class variables in Java?
They can be accessed regardless of whether or not a class object has been instantiated.
They must be initialized with constructors.
II only
I and II
None
I only
In Java, which of the following is (are) true of constructors?
Only one constructor may be present in each class.
A constructor must have the same name as its class.
Argument lists can be passed to constructors.
I, II, and III
I and III only
II only
II and III only
Consider the following Java program segment.
class Foo {
private int x = 1;
public Foo() {x = 2;}
public Foo(int xVal) {x = xVal;}
}
Foo f = new Foo();
What will be the value of f.x at the end of execution of the segment?
1
0
null
2
Which of the following is (are) true of static methods in Java?
They can access non-static variables in their class.
They must be associated with an instantiated object.
I and II
II only
I only
None
Which of the following is an example of a method return-type in Java?
static
final
private
void
Which of the following Java method declarations does not require that the method return a value?
private int myMethod();
public String myMethod();
private static int myMethod();
public void myMethod();
In Java, defining more than one method having the same name within a particular class is called
sharing
overriding
superseding
overloading
Of the following names, which best follows the Java naming convention for a read accessor for variable myVal?
getmyVal()
getmyval()
myVal()
getMyVal()
Which of the following Java program segments will compile and execute without error?
int[] numbers = {1, 2, 3};
for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);
}
int[] numbers = {1, 2, 3};
for (int i = 0; i < numbers.length; i--) {
System.out.println(numbers[i]);
}