This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One Doubt of creating objects of interface..

 
Bijendra S. Rajput
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all

There is one program in KS & BB on page 222.
They have one interface .......

interface Sporty (
void beSporty();
)

and in main class they are instanciating that interface....

Sporty[] SportyThings = new Sporty [3];
I think that...... we can not create a object of a interface ....

Could any body can tell me ?

Thanks,

Bijendra
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look closely you will notice that they are not instantiating the interface, but declaring an array of the interface type. Which means that you will be able to add objects to the array that implements the interface.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic