platform and loadedCars are never instantiated, so they will remain null. carAmount is not initialized either, so it will default to 0. It's important that an object is left in a valid state after construction. If you leave some instance variables null after construction, then a method could call these instance variables without knowing they're null, which results in a NullPointerException.
platform
andloadedCars
are never instantiated, so they will remain null.carAmount
is not initialized either, so it will default to0
. It's important that an object is left in a valid state after construction. If you leave some instance variables null after construction, then a method could call these instance variables without knowing they're null, which results in a NullPointerException.https://github.com/ghazalghorabi/TDA553-lab1/blob/01f3360df2ab6d8a3dae4522fac81312009bb5d9/src/CarTransporter.java#L6-L16