File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface questions" Watch "Interface questions" New topic
Author

Interface questions

Dennis Tribby
Greenhorn

Joined: Jun 04, 2000
Posts: 5
In preparing for the SCJP I have certain doubts regarding interfaces.
Given that an interface can only be extend other interfaces and since it can only contain abstract methods (which have no method body), why bother with them at all?
From the code listed below couldn't we ignore the "implements Runnable" and replace the "public void run()" with "public void myCompute". Since the run(), for example, doesn't do anything I couldn't I substituted my own code? From within the body of an interface can anything else be added beyon abstract methods?
The following code snippet is from Sun's SDK 1.3 API documentation
class PrimeRun implements Runnable {
long minPrime;
PrimeRun(long minPrime) {
this.minPrime = minPrime;
}

public void run() {
// compute primes larger than minPrime
. . .
}
}

I'm guessing that the Runnable (et.al.) interface has some special meaning at the compiler level.. If so, what?
Thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi dennis,
interface is like a skeleton..it can contain non abstract methods also..In ur example, the Runnable interface allows u to create a thread in your class and you need to override the run() method of the Runnable interface...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface questions
 
Similar Threads
Implementing an interface in anonymous class
Threads
is this Ambiguous?
Static methods in Java Interfaces?
Extends vs. Implement?