• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interfaces

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you that makes sense.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic