2

In Java you can create a class, like Bicycle, and then a subclass of that class, RoadBike.

You could then instantiate a RoadBike object like this:

Bicycle bike = new RoadBike();

or like this:

Roadbike bike = new RoadBike();

or even like this:

Object bike = new RoadBike();

My question is, what is the purpose of declaring a specific object, like RoadBike, as a more general type, like Object or Bicycle? Why and when would you do this, and does it take more memory to declare it as a more general object?

Zack
  • 874
  • 1
  • 9
  • 18

0 Answers0