Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 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

HELP ME

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the effect of adding the sixth element to a vector created in the following manner:

new Vector(5, 10);

An IndexOutOfBounds exception is raised.
The vector grows in size to a capacity of 10 elements
The vector grows in size to a capacity of 15 elements
Nothing, the vector will have grown when the fifth element was added
Select the most appropriate answer.

can anyone tell me what is the answer and why?
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ans: The vector grows in size to a capacity of 15 elements.
For Vector, the c'tor you're invoking is:

Initial capacity = 5
capacityIncrement = 10
When you added the 6th element, the Vector had to resize. It will add 10 to the current size (5) which gives 15.
-Peter

[This message has been edited by Peter Tran (edited January 26, 2001).]
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer i believe is
The vector grows in size to a capacity of 15 elements
because the inital was 5 so whenever you go over it , it will be increased to 15 i think that if you go over that , the capacity will be increased proportionaly .
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u guys .
 
Montana has cold dark nights. Perfect for the heat from incandescent light. 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