Win a copy of Functional Reactive Programming this week in the Other Languages 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic