aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "interface" Watch "interface" New topic
Author

interface

ajay solanki
Ranch Hand

Joined: Feb 25, 2008
Posts: 35
Why do we need interface ?

it is used to declare methods and it gives an abstraction of a class,
excepting this any other use of interface.
vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 84
interface can be used for many purposes.you know in java there is no multiple inheritence,so only one class can be extended but we can implement more interfeces at a time.if you do not have interfeces only one class can be extended by your class.if you want to extend Thread class and Exception class at a time what can you do?
use Exception class and Runnable interface...this is one purpose.Interfaces have so many uses...
ajay solanki
Ranch Hand

Joined: Feb 25, 2008
Posts: 35
Tell me other uses of interface in java
Please tell me
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You'll get more out of your studies if you do some research and then come back and tell us.

What have you read about them so far?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ajay solanki
Ranch Hand

Joined: Feb 25, 2008
Posts: 35
i want to know that how does an interface intrect with our system ?

like a Runable interface has only one method that is run, how does it kwon that it is time to invoke run method ?
even Thread class also implements Runable interface?

actully interface is some tough to understand to me.
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
try to look it this way. interface is like a contract between classes. when one class is implementing interface, this implementation guaranties that this class has certain methods that other classes can call.
if you want to make a thread you need a class that implements runnable interface. this way you know you can call start on instance of that class. and it will do whatever is designed in its run method.
hope this helps a bit


<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: interface
 
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
Regarding Interfaces
Writing an Interface
Time Capsule
Home interface or Home Interface stub