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

iterface method

 
tribhuwan soni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi buddy,

if giving more than one body of abstract method in interface when want to implement it in the class could it possible to define only ane abstract method and other not using in the class even keep it only body.


regards
tribhuwan soni
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tribhuwan, I'm sorry but it's hard to follow what you mean. Can you post some code to explain what it is exactly that you want to know?

In an interface, you cannot specify a body for a method. When you create a non-abstract class that implements an interface then all methods of the interface must be implemented in the class.
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I get what you're asking. I believe what you're trying to ask is whether an abstract class that implements an interface must give implementation code for all of the methods in the interface. (If this isn't right, feel free to correct me.)

The answer is no, but any class that extends the abstract class must implement the methods that the abstract class does not.

For example:



The interface A defines two methods. The abstract class B implements one of them, and the concrete class C implements the other.

Does this answer your question?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic