I got it from,
http://www.javabeat.net/javabeat/scjp5/mocks/Generics-part1-6questions.php import java.util.*;
class Vehicle {}
class Car extends Vehicle {}
class Bus extends Vehicle {}
class TestSamp {
public static void main(
String [] args) {
ArrayList<Car> a = new ArrayList<Car>();
a.add(new Car());
ArrayList b = a;
ArrayList<Bus> c = (ArrayList<Bus>
b;
c.add(new Bus());
for (Object obj : b)
System.out.println(obj);
}
}
1.compiler error
2.compiles with warning and gives some output
3.compiles without warning and gives some output
4.copiles and run with no output
Answer they given is: 3
I tried this and when I complied, it showed Note:Recompile with -Xlint:uncheked for details.
is that a warning? i did recompile to get the details and i got 1 warning. if this is true then 2 is the right answer?
please anyone explain me....getting confused.
Preparing Scjp5