• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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 (et.al.) 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 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...
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!