Hi, all,
Here are some sample questions. Please take a look at them, and provide the answers. I have done them, just want to verify the answer some other ranchers. Thanks.
Q-2
Sample Code
String readString() {
char buf[] = new char[80];
Reader in = new InputStreamReader(System.in);
in.read(buf, 0, 80);
return new String(buf);
}
What is wrong with method readString()?
Choice 1
all IO methods must be declared public
Choice 2
an InputStreamReader object can not be bound to standard input
Choice 3
logic to catch exceptions for the InputStream statements is missing
Choice 4
String objects can not be instantiated with a character array
Choice 5
you can not cast InputStreamReader into Reader
Q-3
class A {
int i, j, k;
public A() { i=3; }
public A(int i1) { i = i1; }
public A(int i1, int k1) {
this(i1);
k = k1;
}
}
What is wrong with class A?
Choice 1
there are multiple methods named A()
Choice 2
nothing
Choice 3
a method can not have the same name as its class
Choice 4
all methods must declare return datatypes
Choice 5
methods can not invoke other methods in their own class
Q-4
for(int i=0;i<22;i++) {
if(i<10) {
int j= 2 + i;
}
System.out.println("i: " + i + " j: " + j);
}
What is wrong with the above code?
Choice 1
you can not declare integer i inside the for-loop declaration
Choice 2
variable j is referenced outside its scope
Choice 3
you can not declare variables inside a for-loop
Choice 4
you can not print integer values without converting them to strings
Choice 5
the syntax of the "if" statement is incorrect
Q-5
for(int i=0;i<22;i++) {
if(i<10) {
int j= 2 + i;
}
System.out.println("i: " + i + " j: " + j);
}
What is wrong with the above code?
Choice 1
you can not declare integer i inside the for-loop declaration
Choice 2
variable j is referenced outside its scope
Choice 3
you can not declare variables inside a for-loop
Choice 4
you can not print integer values without converting them to strings
Choice 5
the syntax of the "if" statement is incorrect
Q-6
If memory may be running low, what could free some up?
Choice 1
invoke System.garbageCollection()
Choice 2
reduce the priority of less important threads
Choice 3
invoke System.gc()
Choice 4
make more methods synchronized
Choice 5
call destroy() on any objects you no longer need