File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface questions" Watch "Interface questions" New topic

Interface questions

Dennis Tribby

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 ( interface has some special meaning at the compiler level.. If so, what?
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi dennis,
interface is like a 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:
subject: Interface questions
It's not a secret anymore!