About Question enthuware.ocajp.i.v8.3.1487 :
Posted: Wed May 31, 2017 7:43 am
The question is:
The correct answer is "It will not compile due to //1" instead of "It will not compile due to //3"
You missed an import statement in question body.
Compilation error on line //1 : List can not be resolved to a type.
What will the following code print when compiled and run?
Code: Select all
public class Data{
int value;
Data(int value){
this.value = value;
}
public String toString(){ return ""+value; }
public static void main(String[] args) {
Data[] dataArr = new Data[]{ new Data(1), new Data(2), new Data(3), new Data(4) };
List<Data> dataList = Arrays.asList(dataArr); //1
for(Data element : dataList){
dataList.removeIf( (Data d) -> { return d.value%2 == 0; } ); //2
System.out.println("Removed "+d+", "); //3
}
}
}
You missed an import statement in question body.
Compilation error on line //1 : List can not be resolved to a type.