Which line contains a constructor in this class definition?()
public class Counter { // (1)
int current, step;
public Counter(int startValue, int stepValue) { // (2)
set(startValue);
setStepValue(stepValue); }
public int get() { return current; } // (3)
public void set(int value) { current = value; } // (4)
public void setStepValue(int stepValue) { step = stepValue; } // (5) }
A.Code marked with (1) is a constructor
B.Code marked with (2) is a constructor
C.Code marked with (3) is a constructor
D.Code marked with (4) is a constructor
E.Code marked with (5) is a Constructor
您可能感兴趣的试卷
你可能感兴趣的试题
A.is also called a static member
B.is always a variable
C.is never a method
D.belongs to a single instance, not to the class as a whole
E.always represents an operation
A.what classes are instantiated from.
B.an instance of a class.
C.a blueprint for creating concrete realization of abstractions.
D.a reference to an attribute.
E.a variable.
A.an implementation of an abstraction.
B.an attribute defining the property of a particular abstraction.
C.a category of objects.
D.an operation defining the behavior for a particular abstraction.
E.a blueprint for making operations.
1. public class X {
2. public object m () {
3. object o = new float (3.14F);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. oa[0] = null;
10. return o;
9. }
10. }
When is the float object created in line 3, eligible for garbage collection?()
A. Just after line 5.
B. Just after line 6.
C. Just after line 7.
D. Just after line 8(that is, as the method returns).
public class MethodOver {
private int x, y;
private float z;
public void setVar(int a, int b, float c){
x = a;
y = b;
z = c;
}
}
Which two overload the setVar method?()
A. void setVar (int a, int b, float c){ x = a; y = b; z = c; }
B. public void setVar(int a, float c, int b) { setVar(a, b, c); }
C. public void setVar(int a, float c, int b) { this(a, b, c); }
D. public void setVar(int a, float b){ x = a; z = b; }
E. public void setVar(int ax, int by, float cz) { x = ax; y = by; z = cz; }
1. class A {
2. public String toString () {
3. return “4”;
4. }
5. }
6. class B extends A {
7. public String toString () {
8. return super.toString() + “3”;
9. }
10. }
11. public class Test {
12. public static void main(String[]args) {
13. System.out.printIn(new B());
14. }
15. }
What is the result?()
A. Compilation succeeds and 4 is printed.
B. Compilation succeeds and 43 is printed.
C. An error on line 9 causes compilation to fail.
D. An error on line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 9.
A. Member data have no access modifiers.
B. Member data can be modified directly.
C. The access modifier for methods is protected.
D. The access modifier to member data is private.
E. Methods provide for access and modification of data.
public class Test {
public static void main (String [] args) {
string foo = “blue”;
string bar = foo;
foo = “green”;
System.out.printIn(bar);
}
}
What is the result?()
A. An exception is thrown.
B. The code will not compile.
C. The program prints “null”
D. The program prints “blue”
E. The program prints “green”
2. public class Foo implements Runnable (
3. public void run (Thread t) {
4. system.out.printIn(“Running.”);
5. }
6. public static void main (String[] args) {
7. new thread (new Foo()).start();
8. )
9. )
What is the result?()
A. An exception is thrown.
B. The program exists without printing anything.
C. An error at line 1 causes compilation to fail.
D. An error at line 6 causes the compilation to fail.
E. “Running” is printed and the program exits.
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
最新试题
What is the result?()
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?()
Which two statements are true?()
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()
A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()
What is the result?()
What can be a result?()
What is the result?()
What is the result?()