Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

K&B page no 121 doubt

 
Ranch Hand
Posts: 78
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming an interface, Bounceable, with two methods: bounce(), and
setBounceFactor(), the following class will compile:


setBounceFactor() is with the parameters.. Is it the correct implementation of Interfaces.?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just implementing the methods with empty { } is obviously not a good implementation(though it is correct in terms of the compiler and satisfying the Interface contract). If you implement an Interface, you have to provide definition to all of the methods, unless the implementing class is an Abstract class, in which case you can skip the implementation of methods which you dont want to implement.
 
jas preet
Ranch Hand
Posts: 78
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What actually i wanted to ask is that the Bounceable interface contains the method setBounceFactor() but the implementation class contains the same method with parameter. Is it fine to do that?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it the correct implementation of Interfaces.?



It is technically sound, although the intent would be to implement a behavior that does something that the interface methods allude to.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jas preet wrote:What actually i wanted to ask is that the Bounceable interface contains the method setBounceFactor() but the implementation class contains the same method with parameter. Is it fine to do that?



You can overload the methods(adding new method parameters for the method with the same name), but you should implement all the methods in the Bounceable interface. Is the code which you provided compiling fine?
 
jas preet
Ranch Hand
Posts: 78
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code is not my own..it is there in the KB book at pg no 121.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jas preet wrote:This code is not my own..it is there in the KB book at pg no 121.


Most of us dont have access to the book right away. If its an error, then it will be mentioned in the list of Errata for the book.

Someone with the book might be able to help you. Or you can post the complete code with interface declaration. And in what context it is being used.
 
jas preet
Ranch Hand
Posts: 78
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the code does not compile fine. It gives an error.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jas preet wrote:Yes the code does not compile fine. It gives an error.



>> The code shouldn't compile (As you have said above)- Reason: It doesn't confirm to the Interface contract.
>> What have they given in the K&B book?- Compiles fine? Also in what context have they given this example?

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic