Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
Rancher
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!