-3

I have a class that extends my base class.

class A extends Base {}
class Base{}

//In another class I am trying to override an array list

class C {  ArrayList<Base> it = new ArrayList<Base>()}

class D extends C {ArrayList<A> it = new ArrayList<A>()}

But I am getting an error?

Sholdn't i be able to in class D insantiate it as A is it extends the base? Any other ways to do this?? thanks a ton!!

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
user565660
  • 1,171
  • 3
  • 20
  • 37

1 Answers1

5

You are missing two semicolons:

class C {  ArrayList<Base> it = new ArrayList<Base>(); }
                                                     ^
                                                    !!!

class D extends C {ArrayList<A> it = new ArrayList<A>(); }
                                                       ^
                                                      !!!

And, you need to import java.util.ArrayList;

With that, your code compiles fine.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123