一名朋友和我正在研究 Java。 我们今天正在研究接口,我们讨论了如何使用接口。
我的朋友们所举的例子包括:
IVehicle modeOfTransport1 = new Car();
IVehicle modeOfTransport2 = new Bike();
Where IVehicle is an interface that s implemented in both the car and bike classes. When defining a method that accepts IVehicle as a parameter you can use the interface methods, and when you run the code the above objects work as normal. However, this works perfectly fine when declaring the car and bike as you normally would like this:
Car modeOfTransport1 = new Car();
Bike modeOfTransport2 = new Bike();
因此,我的问题是——为什么在宣布和立即提出