You need to declare car2
as a CarLux
, not a Vehicle
.
CarLux car2 = new CarLux();
That's because your setAr()
method is defined on CarLux
. car2
is currently held in a variable of type Vehicle
, so when you call a method of car2
only the methods declared by Vehicle
will be available.