File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Reference the Interface Or the Class That Implements the Interface?

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some methods defined in an interface UserDAO; something like:

and I have a class MySQLUserDAO that implements UserDAO.
If I want to access the method findUserPassword( String username ) from a class called UserService, I should access the interface or the class that implements the interface? For example, which one is correct:

or

[ November 24, 2003: Message edited by: JiaPei Jen ]
 
Uma Balu
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Generally, we will create only a reference to an interface. Your code,

will not compile because, you are trying to instantiate an interface, which is not possible.
May be, you can use it this way,

Thanks,
Uma.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces are acting as superclasses of the implementing class, because Java doesn't allow multiple inheritence... So the usage of interfaces is devoloped in Java...
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic