1. What is the output ?
public class Test {
public static void main (String [] args) {
try {
badMethod();
System.out.print("E");
}
catch (RuntimeException ex) {
System.out.print("B");
return;
}
catch (Exception ex1) {
System.out.print("C");
return;
}
finally {
System.out.print("D");
}
}
public static void badMethod() {
System.out.print("A");
}
}
a) Compile error b) ABD c) ACD d) AED
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) AED. There is no exception thrown
Correct! AED. There is no exception thrown
2. What is the numerical range of a byte?
a) 0...32767 b) -256...255 c) -128...127
d) 0...255
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) -128...127
Correct! -128...127
3. Which three are valid declarations of a float?
A. float foo = -1;
B. float foo = 1.0;
C. float foo = 42e1;
D. float foo = 2.02f;
E. float foo = 3.03d;
F. float foo = 0x0123;
a) B, D, F b) A, B, D c) A, D, F d) A, D, E
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) A, D, F. Others have loss of precision
Correct! A, D, F. Others have loss of precision
4. Which are valid declarations of a char?
A. char ch1 ="a";
B. char ch2 ='\'';
C. char ch3 ='cafe';
D. char ch4 ="cafe";
E. char ch5 = '\ucafe';
F. char ch6 ='\u0041';
G. char ch7 = (char)true;
a) A, E, F b) B, F, G c) B, E, F d) B, E, G
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) B, E, F
Correct! B, E, F
5. What is the output?
import java.util.TreeSet;
public class Test {
public static void main (String [] args) {
TreeSet ss = new TreeSet();
ss.add("n");
ss.add("c");
ss.add("z");
ss.add("d");
ss.add("f");
ss.add("a");
ss.add("z");
System.out.println(ss);
}
}
a) [n, c, d, f, a, z] b) [n, c, z, d, f, a, z] c) [n, c, z, d, f, a] d) [a, c, d, f, n, z]
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) [a, c, d, f, n, z] TreeSet implements SortedSet interface, and so elements are sorted and no duplicates
Correct! [a, c, d, f, n, z] TreeSet implements SortedSet interface, and so elements are sorted and no duplicates
6. Which of these CANNOT be used as identifiers in Java?
A. false
B. extend
C. enum
D. try
E. synchronous
F. assert
G. case
a) A, C, D, F, G b) A, B, D, E, G c) A, D, E, F, G d) A, C, D, E, F
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) A, C, D, F, G. 'false' is a literal and others are keywords
Correct! A, C, D, F, G. 'false' is a literal and others are keywords
7. What is the output?
public class Test {
public static void main(String [] args) {
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++) {
if (( ++x > 2 ) && (++y > 2)) {
x++;
}
}
System.out.println(x +" "+ y);
}
}
a) 5 2 b) 5 3 c) 6 3 d) 6 4
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is c) 6 3 ++x increments before usage and x++ uses first and then increments
Correct! 6 3 ++x increments before usage and x++ uses first and then increments