多项选择题
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a, b and c at any time? ()
class Counter { int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v--; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec(); }
public synchronized void b() {
i.inc();
j.inc();
k.inc();
System.out.println("b");
i.dec();
j.dec();
k.dec(); }
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}
A.i.v is guaranteed always to be 0 or 1.
B.j.v is guaranteed always to be 0 or 1.
C.k.v is guaranteed always to be 0 or 1
D.j.v will always be greater than or equal to k.v at any give time.
E.k.v will always be greater than or equal to j.v at any give time.
相关考题
-
单项选择题
What will be written to the standard output when the following program is run?() public class Q03e4 { public static void main(String args[]) { String space = " "; String composite = space + "hello" + space + space; composite.concat("world"); String trimmed = composite.trim(); System.out.println(trimmed.length()); } }
A.5
B.6
C.7
D.12
E.13 -
单项选择题
GiventhatfileisareferencetoaFileobjectthatrepresentsadirectory,whichcodefragmentswillsucceedinobtainingalistoftheentriesinthedirectory?()
A.Vector filelist = ((Directory) file).getList();
B.String[] filelist = file.directory();
C.Enumeration filelist = file.contents();
D.String[] filelist = file.list();
E.Vector filelist = (new Directory(file)).files(); -
填空题
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object. class Base { public void print() { System.out.println("base"); } } class Extention extends Base { public void print() { System.out.println("extension"); // insert line of implementation here } } public class Q294d { public static void main(String args[]) { Extention ext = new Extention(); ext.print(); } } Fill in a single line of implementation.()
