This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Interfaces  RSS feed

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the definition of an interface?
In the below test question from JQ+ a Runnable interface is instantiated. I have never seen this before. I thought an interface was to be implemented by a class or extended by a class. What exactly is the definition of an interface?
It is like a class with all the rights of a class?
public class junkf {
public int startHere = 1;
public int endHere = 100;

public static void main(String args []) {
new junkf().go();
}
void go() {
Runnable a = new Runnable() { //Note the use of Runnable
public void run()
{
for (int i = startHere; i <= endHere; i++) { System.out.println(i); }
}
};

Thread t = new Thread(a);
t.start();
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a shorthand for anonymous inner classes constructors. The compiler creates the equivilent of a class extending Object implementing Runnable.
Bill

------------------
author of:
 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you that makes sense.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!