File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface misunderstanding" Watch "Interface misunderstanding" New topic
Author

Interface misunderstanding

thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117
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
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

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: 117
ok got it..remembering these things is slightly difficult for me..forming a logic seems easier.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface misunderstanding
 
Similar Threads
inheriting static members
Question from Enthuware
Why Below Code Is Compile And Executes Successfully.
Question on Threads
method Overriding - Class Bus extends Vehicle, Class Car extends Vehicle