• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interfaces

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About interfaces...
I know we can't create an instance of an inteface like this
this is interface IAbout.
IAbout b = new IAbout();
but i can create it like this why ?
IAbout b[] = new IAbout[4];
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do I think is that four references will be created in array but not instances...
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Your first example tries to create an object, but your second one just declares an empty array. Your second statement:
IAbout[] b = new IAbout[4];
just tells the compiler that you want the b array to have four elements which will reference an IAbout object. By default arrays get initialized when declared, therefore the array b will have 4 null values after the above statement. To use the array you need to fill in good values into it:

Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic