I have an interface “Vehicle” and classes implementing that interface Car, Bicycle, Bike etc.
Can I create a Vector of the interface and assign it instances of the implementing classes?
For ex:
Vector<Vehicle> vi;
vi.add(0, new Car());
vi.add(1, new Bicycle());
etc.
So at runtime, I can simply check the index and invoke the required function?
Sure, you can. It’s a classical example of a polymorphism usage in runtime.
Demo