Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!