Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface misunderstanding

 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Wayan Saryada
Ranch Hand
Posts: 105
IntelliJ IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok got it..remembering these things is slightly difficult for me..forming a logic seems easier.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic