Core Java Practice Test
Core Java Practice Test
answer : 1 & 2
2. What will happen when you attempt to compile and run the following code?
public class TadKebab{
public static void main(String argv[]){
new TadKebab();
}
private TadKebab(){
String[] Sa = {"Sam Smith", "John Smith"};
getName(Sa);
System.out.print(Sa[0]);
}
Answer : 3
3. Given the code. What is the result?
public class TrickyNum<X extends Object> {
private X x;
public TrickyNum(X x) {
this.x = x;
}
C) "1.0" is printed.
D) "1" is printed.
Answer : B
Collections.reverse(list);
Iterator iter = list.iterator();
C) Nothing is printed
D) Compilation fails
Answer : D
A) A method with the same signature as a private final method in class Z can be
implemented in a subclass of Z.
B) A final method in class Z can be abstract if and only if Z is abstract.
D) A private static method can be called only within other static methods in class Z.
Answer A,C,D
Answer C.D
B) "2" is printed
C) Compilation fails
Answer : 2
8. Given the code. What is the result?
C) "book" is printed.
Answer : A
9. Give a piece of code. Which two are possible results? (Select two)
C) 0, 2, 4, 6, 8, 10, 2, 4,
Answer: B
book(shortRoom);
book(intRoom);
}
}
A) SHORT LONG
B) short LONG
C) Compilation fails
Answer C
import java.io.*;
class Room {
}
A) Compilation fails.
Answer : B
B) "exception" is printed.
D) Compilation fails.
Answer : D
import java.io.*;
Answer : C
14. Given the code. What is the output?
A) one.two.three.
Answer : C
C) d e h
D) d f i
E) c f i
F) c e h
Answer : C
16. Which code, inserted inserted at line labeled "//some code goes her", allows
the class Test to be compiled?
class Util {
public enum State{ACTIVE, DELETED, INACTIVE}
}
Answer: B
17. Given the code. What is the result?
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@Override
public String toString() {
return this.str;
}
Collections.sort(list);
for (Object o : list) {
System.out.print(o + " ");
}
}
}
C) Compilation fails.
Answer : C
18. Given the code. What is the result?
public class TrickyNum<X extends Object> {
private X x;
public TrickyNum(X x) {
this.x = x;
}
A) Compilation fails.
C) "1.0" is printed.
D) "1" is printed.
Answer : B
20 Given the code. Select correct calls of methods. (Select all that apply)
import java.util.*;
class Empty {
}
A) doStuff1(list1);
B) doStuff2(list2);
C) doStuff2(list1);
D) doStuff3(list1);
E) doStuff3(list2);
F) doStuff1(list2);
Answer A,D,B