Given the following interface definition, which definitions are valid?()
interface I {
void setValue(int val);
int getValue();
}
DEFINITION a:
(a) class a extends I { int value;
void setValue(int val) { value = val;
}
int getValue() {
return value;
}
}
DEFINITION b:
(b) interface b extends I {
void increment();
}
DEFINITION c:
(c) abstract class c implements I {
int getValue() {
return 0;
} abstract void increment();
}
DEFINITION d:
(d) interface d implements I { void increment(); }
DEFINITION e:
(e) class e implements I { int value;
public void setValue(int val) { value = val; } }
A.Definition a.
B.Definition b.
C.Definition c.
D.Definition d.
E.Definition e.
您可能感兴趣的试卷
你可能感兴趣的试题
What will be the result of attempting to compile and run the following program?()
public class Q28fd {
public static void main(String args[]) {
int counter = 0;
l1:
for (int i=10; i<0; i--) {
l2: int j = 0;
while (j < 10) {
if (j > i) break l2;
if (i == j) {
counter++;
continue l1;
}
}
counter--;
}
System.out.println(counter);
}
}
A.The program will fail to compile.
B.The program will not terminate normally.
C.The program will write 10 to the standard output.
D.The program will write 0 to the standard output.
E.The program will write 9 to the standard output.
A._class
B.$value$
C.zer@
D.¥ngstr
E.2muchuq
Which method implementations will write the given string to a file named "file", using UTF8 encoding?()
IMPLEMENTATION a:
public void write(String msg) throws IOException {
FileWriter fw = new FileWriter(new File("file"));
fw.write(msg);
fw.close();
}
IMPLEMENTATION b:
public void write(String msg) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("file"), "UTF8"); osw.write(msg);
osw.close();
}
IMPLEMENTATION c:
public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file"));
fw.setEncoding("UTF8");
fw.write(msg);
fw.close(); }
IMPLEMENTATION d:
public void write(String msg) throws IOException { FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8");
fw.write(msg); fw.close();
}
IMPLEMENTATION e:
public void write(String msg) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter( new OutputStream(new File("file")), "UTF8" );
osw.write(msg);
osw.close();
}
A.Implementation a.
B.Implementation b.
C.Implementation c.
D.Implementation d.
E.Implementation e.
Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?()
import java.awt.*;
public class Q1e65 {
public static void main(String args[]) {
Window win = new Frame();
Button but = new Button("button");
// insert code fragment here win.setSize(200, 200);
win.setVisible(true);
}
}
A.win.setLayout(new BorderLayout()); win.add(but);
B.win.setLayout(new GridLayout(1, 1)); win.add(but);
C.win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);
D.win.add(but);
E.win.setLayout(new FlowLayout()); win.add(but);
A.The rectangle drawn will have a total width of 5 pixels.
B.The rectangle drawn will have a total height of 6 pixels.
C.The rectangle drawn will have a total width of 10 pixels.
D.The rectangle drawn will have a total height of 11 pixels.
What will be written to the standard output when the following program is run?()
public class Qcb90 {
int a;
int b;
public void f() { a = 0;
b = 0;
int[] c = { 0 };
g(b, c);
System.out.println(a + " " + b + " " + c[0] + " ");
}
public void g(int b, int[] c) {
a = 1; b = 1; c[0] = 1; }
public static void main(String args[]) {
Qcb90 obj = new Qcb90();
obj.f();
}
}
A.0 0 0
B.0 0 1
C.0 1 0
D.1 0 0
E.1 0 1
What will be written to the standard output when the following program is run?()
public class Q8499 {
public static void main(String args[]) {
double d = -2.9;
int i = (int) d;
i *= (int) Math.ceil(d);
i *= (int) Math.abs(d);
System.out.println(i);
}
}
A.12
B.18
C.8
D.9
E.27
A.Set extends Collection.
B.All methods defined in Set are also defined in Collection.
C.List extends Collection.
D.All methods defined in List are also defined in Collection.
E.Map extends Collection.
Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?()
CODE FRAGMENT a:
public static void main(String args[]) {
if (args.length != 0)
System.out.println(args[args.length-1]);
}
CODE FRAGMENT b:
public static void main(String args[]) {
try { System.out.println(args[args.length]); }
catch (ArrayIndexOutOfBoundsException e) {}
}
CODE FRAGMENT c:
public static void main(String args[]) {
int ix = args.length;
String last = args[ix];
if (ix != 0) System.out.println(last);
}
CODE FRAGMENT d:
public static void main(String args[]) {
int ix = args.length-1;
if (ix > 0) System.out.println(args[ix]);
}
CODE FRAGMENT e:
public static void main(String args[]) {
try { System.out.println(args[args.length-1]);
}catch (NullPointerException e) {}
}
A.Code fragment a.
B.Code fragment b.
C.Code fragment c.
D.Code fragment d.
E.Code fragment e.
最新试题
Which statement is true?()
What is the appropriate definition of the hashCode method in class Person?()
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()
What can be a result?()
Which two are possible results?()
What is the result?()
Which statement is true?()
What is the result?()
Given: foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()
Which three changes should be made to adapt this class to be used safely by multiple threads?()