import java.util.*;
public 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 <Car> b = a;
ArrayList<Bus> c = (ArrayList<Bus>
b;
c.add(new Bus());
for (Object obj : b)
System.out.println(obj);
Options:
1.compiler error
2.compiles with warning and gives some output
3.compiles without warning and gives some output
4.compiles and run with no output
answer 3) ArrayList b = a; This assignment assigns a typesafe arraylist in to a non-typesafe arraylist, So this assignment causes warning during compilation.
===============================================================================
When I wrote this program, I got compile error because "Incompatible cast(ArrayList<Car>
to (ArrayList<Bus>
". Even the answer which they have given is also conflict. Can anybody help me?