Here b=new ArrayList<Car>(), when we add new bus then it is adding in a car arraylist. So it can not compile. I want to make sure that I am right or not?
class Box<T> { private T theObject; public Box(T arg) { theObject = arg; } public Box() { } } class Test { public static void main(String[] args) { Box<String> b1 = new Box<String>("Java"); //line 1 Object<String> b2 = new Box<String>("Struts"); //line 2 Box<String> b3 = new Box("EJB"); //line 3 Box b4 = new Box<String>("Ajax"); //line 4 Object b5 = new Box<Object>(); //line 5 } }
what will be the effect of the program?
a)compile time error at line 5 only b)compile time error at line 2 only c)compile time error at line 2 and line 5 d)compile time error at line 3 and line 4 e)Run time error
Answer : b
Explanation: Object class doesnot take any parameters
Why is it so? I am not getting. Can anyone explain?