question 21)
what will be output by the following code?
public class myfor{
public static void main(string argv[]){
int i;
int j;
outer:
for (i=1;i <3;i++)
inner:
for(j=1; j<3; j++) {
if (j==2)
continue outer;
system.out.println("value for i=" + i + " value for j=" +j);
}
}
}
1) value for i=1 value for j=1
2) value for i=2 value for j=1
3) value for i=2 value for j=2
4) value for i=3 value for j=1
question 22)
which statement is true of the following code?
public class agg{
public static void main(string argv[]){
agg a = new agg();
a.go();
}
public void go(){
dsross ds1 = new dsross("one");
ds1.start();
}
}
class dsross extends thread{
private string stname="";
dsross(string s){
stname = s;
}
public void run(){
notwait();
system.out.println("finished");
}
public void notwait(){
while(true){
try{
system.out.println("waiting");
wait();
}catch(interruptedexception ie){}
system.out.println(stname);
notifyall();
}
}
}
1) it will cause a compile time error
2) compilation and output of "waiting"
3) compilation and output of "waiting" followed by "finished"
4) runtime error, an exception will be thrown
question 23)
which of the following methods can be legally inserted in place of the comment //method here ?
class base{
public void amethod(int i) { }
}
public class scope extends base{
public static void main(string argv[]){
}
//method here
}
1) void amethod(int i) throws exception {}
2) void amethod(long i)throws exception {}
3) void amethod(long i){}
4) public void amethod(int i) throws exception {}
question 24)
which of the following will output -4.0
1) system.out.println(math.floor(-4.7));
2) system.out.println(math.round(-4.7));
3) system.out.println(math.ceil(-4.7));
4) system.out.println(math.min(-4.7));
question 25)
what will happen if you attempt to compile and run the following code?
integer ten=new integer(10);
long nine=new long (9);
system.out.println(ten + nine);
int i=1;
system.out.println(i + ten);
1) 19 followed by 20
2) 19 followed by 11
3) compile time error
4) 10 followed by 1
question 26)
if you run the code below, what gets printed out?
string s=new string("bicycle");
int ibegin=1;
char iend=3;
system.out.println(s.substring(ibegin,iend));
1) bic
2) ic
3) icy
4) error: no method matching substring(int,char) 7*({B.w; ^RAp[
question 27)
if you wanted to find out where the position of the letter v (ie return 2) in the string s containing "java",which of the following could you use?
1) mid(2,s);
2) charat(2);
3) s.indexof('v');
4) indexof(s,'v');
question 28)
given the following declarations
string s1=new string("hello")
string s2=new string("there");
string s3=new string();
which of the following are legal operations?
1) s3=s1 + s2;
2) s3=s1-s2;
3) s3=s1 & s2;
4) s3=s1 && s2
question 29)
what is the result of the following operation?
system.out.println(4 | 3);
1) 6
2) 0
3) 1
4) 7
question 30)
public class myclass1 {
public static void main(string argv[]){ }
/*modifier at xx */ class myinner {}
}
what modifiers would be legal at xx in the above code?
1) public
2) private
3) static
4) friend
责任编辑:小草