1. Which two can be used to create a new Thread?
A. Extend java.lang.Thread and override the run() method.
B. Extend java.lang.Runnable and override the start() method.
C. Implement java.lang.Thread and implement the run() method.
D. Implement java.lang.Runnable and implement the run() method.
E. Implement java.lang.Thread and implement the start() method.
a) C & D b) A & D c) B & D d) D & E
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is b) A & D.
Correct! A & D.
2. The following is NOT an example of a data type
a) int b) double c) public
d) void
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) public - it is an access specifier
Correct! public - it is an access specifier
3. What is the output?
public class Test{
public static void main(String[] args) {
try {
Float f1 = new Float("3.0");
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e) {
System.out.println("bad number");
}
}
}
a) bad number b) Compile Error c) 9.0 d) 333.0
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) 9.0 Upgrades to double
Correct! 9.0 Upgrades to double
4. You need to store elements in a collection that guarantees that no duplicates are stored.
Which one of the following interfaces provide that capability?
a) java.util.List b) java.util.Collection c) java.util.Map d) None of the above
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) None of the above. You need to use Set
Correct! None of the above. You need to use Set
5. Which is true about a method-local inner class?
a) It must be marked final b) It can be marked abstract c) It can be marked static d) It can be marked public
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is b) It can be marked abstract It can be marked final, but not compulsory
Correct! It can be marked abstract It can be marked final, but not compulsory
6. A constructor
A. can throw an excepton
B. is used to create objects
C. may be declared private
D. can be overloaded
a) A, B, C b) B, C, D c) A, B, D d) All of them
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) All are true of constructor
Correct! All are true of constructor
7. What is the output?
public class Test {
public static void main(String[] args) {
System.out.println(1+2+3+"4");
}
}