This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes regarding interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regarding interface" Watch "regarding interface" New topic
Author

regarding interface

laxmidhar prad
Ranch Hand

Joined: Feb 05, 2006
Posts: 33
sir,If interface has got four methods,and I like to implement only two methods, how this could be achieved?
Jody Brown
Ranch Hand

Joined: Nov 09, 2005
Posts: 43
If you mark the class implementing the interface as abstract, you only need to provide either partial, or default implementations of the method stubs defined in the interface. This type of class is typically called an Adapter. The remaining methods will then need to be implemented fully in a concrete subclass that inherits from this Adapter.

Be aware however, that by marking a class as abstract, you cannot instantiate it. You will have to instantiate a concrete subclass that has implementations of all of the methods defined by the interface.
Matt Harrah
Ranch Hand

Joined: Aug 05, 2006
Posts: 54
Eventually, instantiated classes that implement the interfaces must have a method that implements the methods on the interface.

However, if the methods on the interface do not apply in a particular situation or should not be called on a specific class that implements that interface, you can do this:
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: regarding interface
 
It's not a secret anymore!