| Author |
Interface misunderstanding
|
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
Vehicle.java :
landVehicle.java //excuse for not following naming convention for class name..
VehicleProgram.java
hey guys,
see the above code..in the VehicleProgram.java file,
the line vehicle1.pedalChange(3); is not compiling..but i dont get it..
i mean vehicle1 is a reference to an object of type LandWaterVehicle. so the method call should be legal right? i mean thats the whole point of run time displatch isnt it?
|
on job hunt
|
 |
I Wayan Saryada
Ranch Hand
Joined: Feb 05, 2004
Posts: 83
|
|
|
It is because the Vehicle interface doesn't have the pedalChange() method. The pedalChange() method is defined in the WaterVehicle interface. The LandWaterVehicle can be referenced by the Vehicle type because this class indirectly implements the Vehicle interface. But when you call the method from the Vehicle type it will not understand the call to pedanChange(). This interface only know how to brake() and speedUp().
|
Website: Learn Java by Examples
|
 |
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
|
ok got it..remembering these things is slightly difficult for me..forming a logic seems easier.
|
 |
 |
|
|
subject: Interface misunderstanding
|
|
|