This is a question in one of the mock exams. Can any body tell me the right answer with some explanation regarding that
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
you can not cast InputStreamReader into Reader
Choice 2
String objects can not be instantiated with a character array
Choice 3
logic to catch exceptions for the InputStream statements is missing
Choice 4
an InputStreamReader object can not be bound to standard input
Choice 5
all IO methods must be declared public
question no 2
public int m1(int x) {
int count=1;
try {
count += x;
count += m2(count);
count++;
}
catch(ArithmeticException e) { count -= x; }
finally { count += 3; }
count++;
return count;
}
When m1(2) is invoked, m2() returns a value of 2 and m1() returns ________.
Choice 1
5
Choice 2
6
Choice 3
7
Choice 4
10
Choice 5
nothing. The system exits