|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
Do you have paypal account? Click Here to pay now and get the questions.
|
|
SCJP 5.0 Objective - 6(10 Questions)
2) What will be the output of the following program?
package scjp5_0.chap06;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Ques01 {
public static void main(String[] args) {
List<Box> boxes = Arrays.asList(new Box(10), new Box(-1), new Box(5), new Box(2));
Collections.sort(boxes, new BoxComparator());
for (Object box : boxes){
System.out.print(((Box)box).getSize() + " ");
}
}
}
class Box{
public int size;
public Box(int size){
this.size = size;
}
public int getSize(){
return size;
}
}
class BoxComparator implements Comparator<Box>{
@Override
public int compare(Box one, Box two) {
if (one.getSize() == two.getSize()){
return 0;
}else if (one.getSize() < two.getSize()){
return 1;
}
return -1;
}
}
- The program will throw a run-time ClassCastException.
- The program will compile to produce the output '10 -1 5 2'.
- The program will compile to produce the output '-1 2 5 10'.
- The program will compile to produce the output '10 5 2 -1'.
Answer
2)d
The objects of type Box have been arranged in descending order and hence the output will be '10 5 2 -1'.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|