• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

INterface should have implemetation

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


here ExecutorService is an interface and Executors.newFixedThreadPool(NTHREDS); return a n intreface ,how it is possible?,an interface should have implementation class ?
 
Ranch Hand
Posts: 180
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanjey,

Here actually the type of reference is an interface but it is actually
poniting to an implementation of ExecutorService.

The method Executors.newFixedThreadPool(NTHREDS); actually
returns an implementation of ExecutorService.

cheers,
Saurav
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's perfectly ok to make a variable of a type that is an interface refer to an object of a class that implements the interface. For example, you can write:

Note that List is an interface, and ArrayList is a class that implements the List interface. The rest of the program, that uses list, only needs to know that it is an object of a class that implements List; it doesn't need to know that it's actually an ArrayList (or some other implementation such as LinkedList).

Likewise, the method Executors.newFixedThreadPool returns an object that's an instance of a class that implements the ExecutorService interface. You don't need to know what that exact class is to be able to use the ExecutorService.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic