• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems in extending interface

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am extending an existing Interface and am getting the compile error
'Interface method cannot have body'
How do I add a method to an existing interface without having to implement every single method?
My attempt so far is to start with...
public interface NewUser extends User {
public String newMethod () { return ("----"); }
}
TIA
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have got some basic concepts mixed up there, mate.
An interface provide method signatures, then some class implements the interface by providing method bodies for those methods.
Try to find some stuff on the benefits of separtating interface from implementation to understand why it is so.
What you may want to do is -
extend the interface as
public interface NewUser extends User{
public String newMethod();
}
This adds one more method to those specified by the User interface that the implementation class has to implement. For example,
public class NewUserImpl implements NewUser{
public String newMethod (){
return ("----");
}
//Implementation of other methods specified by User interface
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic