1

Suppose I have a main class Vehicle and it's sub class Car. If i create an instance of car like:

Car honda = new Car();

Does this also create and instance of the Vehicle class aswell?

RishtarCode47
  • 327
  • 4
  • 15

1 Answers1

2

The expression new Car() will create a single Car instance. Since Car is a subclass of Vehicle, this instance is itself also a Vehicle instance. In particular, your Car instance will have all methods of the Vehicle class.

So, the answer to your question is: Yes, a Vehicle instance is created. But this is the same instance as the Car instance.

Hoopje
  • 12,378
  • 7
  • 31
  • 48