Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Interface questions  RSS feed

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 can't beleive you just said that. Now I need to calm down with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!