aspose file tools
The moose likes Beginning Java and the fly likes Interface misunderstanding Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Interface misunderstanding" Watch "Interface misunderstanding" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Interface misunderstanding
 
Similar Threads
Question on Threads
inheriting static members
method Overriding - Class Bus extends Vehicle, Class Car extends Vehicle
Why Below Code Is Compile And Executes Successfully.
Question from Enthuware