Quiz Java
Geek Time - Janvier 2017
Khaled HALLEB
Consultant - OLBATI
OLBATI © 2016 - Geek Time November 2016 2
Question 1
TreeMap class is used to implement which collection interface. Select the one correct answer
A. Set
B. SortedSet
C. List
D. Tree
E. SortedMap
OLBATI © 2016 - Geek Time November 2016 3
Question 2
Q2. How can you force garbage collection of an object?
A. Garbage collection cannot be forced.
B. Call System.gc().
C. Call System.gc() passing in a reference to the object to be garbage collected.
D. Call Runtime.gc().
E. Set all references to the object to new values(null, for example).
OLBATI © 2016 - Geek Time November 2016 4
Question 3
3. Given the following code:
public class Example {
public static void main(String args[]) {
Date d1 = new Date (99, 11, 31);
Date d2 = new Date (99, 11, 31);
method(d1, d2);
System.out.println("d1 is " + d1
+ "nd2 is " + d2);
}
public static void method(Date d1, Date d2) {
d2.setYear (100);
d1 = d2;
}}
Which one or more of the following correctly describe the behavior when this
program is compiled and run?
a) compilation is successful and the output is:
d1 is Fri December 31 00:00:00 GMT 1999
d2 is Fri December 31 00:00:00 GMT 1999
b) compilation is successful and the output is:
d1 is Fri December 31 00:00:00 GMT 1999
d2 is Sun December 31 00:00:00 GMT 2000
c) compilation is successful and the output is:
d1 is Sun December 31 00:00:00 GMT 2000
d2 is Sun December 31 00:00:00 GMT 2000
d) the assignment 'd1 = d2' is rejected by the compiler because the Date class cannot overload the operator '='.
e) the expression (d1 is " + d1 + "nd2 is " + d2) is rejected by the compiler because the Date class cannot overload the
operator '+'.
OLBATI © 2016 - Geek Time November 2016 5
Réponse 1
TreeMap class is used to implement which collection interface. Select the one correct answer
Correct Answer: E
OLBATI © 2016 - Geek Time November 2016 6
Réponse 2
Q2. How can you force garbage collection of an object?
Correct Answer: A
OLBATI © 2016 - Geek Time November 2016 7
Réponse 3
3. Given the following code:
public class Example {
public static void main(String args[]) {
Date d1 = new Date (99, 11, 31);
Date d2 = new Date (99, 11, 31);
method(d1, d2);
System.out.println("d1 is " + d1
+ "nd2 is " + d2);
}
public static void method(Date d1, Date d2) {
d2.setYear (100);
d1 = d2;
}}
Correct Answer: B
OLBATI © 2016 - Geek Time November 2016 8
Thanks !
Any questions ?
khaled.halleb@olbati.com

Geek Time Janvier 2017 : Quiz Java

  • 1.
    Quiz Java Geek Time- Janvier 2017 Khaled HALLEB Consultant - OLBATI
  • 2.
    OLBATI © 2016- Geek Time November 2016 2 Question 1 TreeMap class is used to implement which collection interface. Select the one correct answer A. Set B. SortedSet C. List D. Tree E. SortedMap
  • 3.
    OLBATI © 2016- Geek Time November 2016 3 Question 2 Q2. How can you force garbage collection of an object? A. Garbage collection cannot be forced. B. Call System.gc(). C. Call System.gc() passing in a reference to the object to be garbage collected. D. Call Runtime.gc(). E. Set all references to the object to new values(null, for example).
  • 4.
    OLBATI © 2016- Geek Time November 2016 4 Question 3 3. Given the following code: public class Example { public static void main(String args[]) { Date d1 = new Date (99, 11, 31); Date d2 = new Date (99, 11, 31); method(d1, d2); System.out.println("d1 is " + d1 + "nd2 is " + d2); } public static void method(Date d1, Date d2) { d2.setYear (100); d1 = d2; }} Which one or more of the following correctly describe the behavior when this program is compiled and run? a) compilation is successful and the output is: d1 is Fri December 31 00:00:00 GMT 1999 d2 is Fri December 31 00:00:00 GMT 1999 b) compilation is successful and the output is: d1 is Fri December 31 00:00:00 GMT 1999 d2 is Sun December 31 00:00:00 GMT 2000 c) compilation is successful and the output is: d1 is Sun December 31 00:00:00 GMT 2000 d2 is Sun December 31 00:00:00 GMT 2000 d) the assignment 'd1 = d2' is rejected by the compiler because the Date class cannot overload the operator '='. e) the expression (d1 is " + d1 + "nd2 is " + d2) is rejected by the compiler because the Date class cannot overload the operator '+'.
  • 5.
    OLBATI © 2016- Geek Time November 2016 5 Réponse 1 TreeMap class is used to implement which collection interface. Select the one correct answer Correct Answer: E
  • 6.
    OLBATI © 2016- Geek Time November 2016 6 Réponse 2 Q2. How can you force garbage collection of an object? Correct Answer: A
  • 7.
    OLBATI © 2016- Geek Time November 2016 7 Réponse 3 3. Given the following code: public class Example { public static void main(String args[]) { Date d1 = new Date (99, 11, 31); Date d2 = new Date (99, 11, 31); method(d1, d2); System.out.println("d1 is " + d1 + "nd2 is " + d2); } public static void method(Date d1, Date d2) { d2.setYear (100); d1 = d2; }} Correct Answer: B
  • 8.
    OLBATI © 2016- Geek Time November 2016 8 Thanks ! Any questions ? khaled.halleb@olbati.com