Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 02:44 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Implementing Interface
I have written following interface with 3 abstract methods. Now class implementing this interface have to overwrite all of these 3 methods.

Code:
public interface Mapper { public void createSchema(); public int getNoOfClasses(); public void setHost(String hostName); }
I have a situation where one class should implement all of these 3 methods and other should only implement createSchema method. How this is possible using this interface.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-06-2007, 06:10 PM
Member
 
Join Date: Dec 2007
Posts: 4
ldb88 is on a distinguished road
The other class should not implement this interface if it shouldn't implement all the functions. You could just put something like
Code:
public int getNoOfClasses(){ }
depending on what is required. It might be better if you had two interfaces.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 11:09 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
You must provide the method declaration for each method defined in the implemented interface. What you do in the method body is up to you.
In pseudo code:
Code:
public interface Mapper { public void createSchema(); public int getNoOfClasses(); public void setHost(String hostName); } class NeedAllMethods implements Mapper { public void createSchema() { // implementation... } public int getNoOfClasses() { // implementation... return intValue; } public void setHost(String hostName) { // implementation... } } class NeedOnlyOne implements Mapper { public void createSchema() { // no-op okay } public int getNoOfClasses() { // no-op okay but you must // return an int value. return 0; } public void setHost(String hostName) { // no-op okay } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
An interface extending an interface(II) JavaForums Java Blogs 0 03-12-2008 05:00 PM
Implementing an interface bugger Advanced Java 1 01-09-2008 03:35 PM
Implementing ActionListener interface JavaForums Java Blogs 0 12-19-2007 11:54 PM
Creating a Thread (implementing Java Runnable Interface) JavaForums Java Blogs 0 12-19-2007 11:31 AM
Implementing Serializable interface javaplus Advanced Java 4 12-18-2007 02:29 PM


All times are GMT +3. The time now is 04:33 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org