File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Interface misunderstanding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface misunderstanding" Watch "Interface misunderstanding" New topic

Interface misunderstanding

thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 119 : //excuse for not following naming convention for class name..

hey guys,

see the above the 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
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 105

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: 119
ok got it..remembering these things is slightly difficult for me..forming a logic seems easier.
I agree. Here's the link:
subject: Interface misunderstanding
It's not a secret anymore!