This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes iterface method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "iterface method" Watch "iterface method" New topic
Author

iterface method

tribhuwan soni
Greenhorn

Joined: May 23, 2007
Posts: 6
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

Joined: Aug 16, 2005
Posts: 14597
    
  24

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: iterface method