question 9:
what code placed after the comment:
// start for loop
would populate the elements of the array ia[] with values of the variables i ?
public class lin{
public static void main(string argv[]){
lin l = new lin();
l.amethod();
}
public void amethod(){
int ia[] = new int[4];
// start for loop
{
ia[i] = i;
system.out.println(ia[i]);
}
}
}
a. for(int i=0; i
b. for (int i=0; i
c. for(int i=0; i<4; i++)
d. for(int i=0; i
question 10:
consider the following code:
integer s = new integer(9);
integer t = new integer(9);
long u = new long(9);
which test would return true?
a. (s==u)
b. (s==t)
c. (s.equals(t))
d. (s.equals(9))
e. (s.equals(new integer(9))
question 11:
which of the following is successfully create an instance of the vector class and add an element?
a. vector v = new vector(99);
v[1]=99;
b. vector v = new vector();
v.addelement(99);
c. vector v = new vector();
v.add(99);
d. vector v = new vector(100);
v.addelement(“99”);
question 12:
what will happen when you attempt to compile and run the following code?
class base{
private void amethod(int ibase){
system.out.println(“base.amethod”);
}
}
class over extends base{
public static void main(string argv[]){
over o = new over();
int ibase=0;
o.amethod(ibase);
}
public void amethod(int iover){
system.out.println(“over.amethod”);
}
}
a. compile time error complaining that base.amethod is private
b. runtime error complaining that base.amethod is private
c. output of base.amethod
d. output of over.amethod
question 13:
what will happen if you try to compile and run the following code?
public class myclass
public static void main(string arguments[]){
amethod(arguments);
}
public void amethod(string[] arguments)
system.out.println(arguments);
system.out.println(arguments[1]);
}
}
a. error can't make static reference to void amethod
b. error method main not correct
c. error array must include parameter
d. error amethod must be declared with string
question 14:
if you wanted to find out where the position of the letter v (i.e. return 2) in the string s containing “java”, which of the following could you use?
a. mid(2,s);
b. charat(2);
c. s.indexof(‘v');
d. indexof(s,'v');
question 15:
what will happen when you attempt to compile and run the following code?
public class bground extends thread{
public static void main(string argv[]){
bground b = new bground();
b.run();
}
public void start(){
for (int i=0;i<10;i++){
system.out.println(“value of i=” + i);
}
}
}
a. a compile time error indicating that no run method is defined for the thread class
b. a run time error indicating that no run method is defined for the thread class
c. clean compile and at run time the values 0 to 9 are printed out
d. clean compile but no output at runtime
question 16:
what will happen when you compile the following code?
public class myclass{
static int i;
public static void main(string argv[]){
system.out.println(i);
}
}
a. error variable i may out have been initialized
b. null
c. 1
d. 0(cn-java)
闽公网安备 35060202000074号