Wrong! The correct answer is b) program. String is immutable.
Correct! program. String is immutable.
3. Which of the following methods are of Collection interface?
A. remove(Object o)
B. clear()
C. get(int index)
D. iterator()
a) All of them b) A, B, C c) A, C, D d) A, B, D
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) A, B, D get(int index) belongs to List
Correct! A, B, D get(int index) belongs to List
4. What is the output?
public class Test {
private int a;
public int calculate() {
try {
int a = 5*5;
}
catch(Exception e){
}
return a;
}
public static void main(String[] args) {
System.out.println(new Test().calculate());
}
}
a) Compile error b) Exception thrown c) 25 d) 0
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) 0, scope of local variable 'a' is within try block
Correct! 0, scope of local variable 'a' is within try block
5. What is the output?
public class TestClass {
public static void main(String[] args) {
for(int i=1;i<=5;i++){
if(i==3) continue;
System.out.print(i+" ");
if(i==3) break;
}
}
}
a) 1 2 b) 1 2 3 4 5 c) 1 2 4 5 d) Compilation fails
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is c) 1 2 4 5, continue prevents the break happening at i=3 and 3 is never printed
Correct! 1 2 4 5, continue prevents the break happening at i=3 and 3 is never printed