Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems in extending interface

 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • 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
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • 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
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic