Your SedanCar class is in a different package than the AbstractVehicle class. protected can only be obtained from the same package or from subclasses.
In the case of SedanCar :
SedanCar sedan = new SedanCar(); sedan.speedFactor();
You call the protected method from one package: OK. SedanCar is in the car package and the main() method is in the class that is in the car package (actually the same class).
In the case of AbstractVehicle :
AbstractVehicle vehicle = new SedanCar(); vehicle.speedFactor();
You are trying to call the protected method, but from another package: NOT OK. The main() method from which you are trying to call it is in the car package, and AbstractVehicle is in the vehicle package.
Understand this basically:
You have a variable of type AbstractVehicle , which is declared in another package ( vehicle ). It may or may not contain the dynamic type SedanCar . In your case, this is true, but it may also contain an instance of any other subclass defined in another package, for example. in a sportcar . And since you are in the car package ( main() method), you are not allowed to call vehicle.speedFactor() (which is protected by AbstractVehicle.speedFactor() ).
source share