• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How is Vector's hasnext() & next() called implicitly ??

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


What will be the out put and how?? (Source-Examulator.com)
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

can you please also include the options that are given with the question , so that we can interpret better.
Btw, where did you get the notion that these two methods in Vector are called implicitly?
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

piya rai wrote:hi,

can you please also include the options that are given with the question , so that we can interpret better.
Btw, where did you get the notion that these two methods in Vector are called implicitly?


Ok,, here are the options:-
1. Compile time error, malformed for loop
2. Compile time error caused by the attempt to create the static Vector class.
3. Compilation error,the for loop requires a String parameter not Object.
4. Compilation and output of each element of the Vector object.
 
mansi gupte
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok,

my answer would be

3. Compilation error,the for loop requires a String parameter not Object.

firstly , the for is used to loop through the collection.I wonder why they haven't mentioned the hasnext() and next() methods , as these two are used to check if there is a element ahead in the collection and return that element respectively.The answer is my assumption , wait for others to reply.


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

piya rai wrote:ok,
wait for others to reply.



Ya, Let the others to involve....
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My answer is the number 4. Compilation and output of each element of the Vector object.

You are casting to Object when you go across the vector and then you are casting again to String when you print the elements.
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Victor Fernandez wrote:My answer is the number 4. Compilation and output of each element of the Vector object.

You are casting to Object when you go across the vector and then you are casting again to String when you print the elements.


Hi Victor, Could you please elaborate the whole flow of the program (I am confused with the call of hasNext() & next()) as it is not mentioned in the code any where...
 
Victor Fernandez
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sunil langeh wrote:

Victor Fernandez wrote:My answer is the number 4. Compilation and output of each element of the Vector object.

You are casting to Object when you go across the vector and then you are casting again to String when you print the elements.


Hi Victor, Could you please elaborate the whole flow of the program (I am confused with the call of hasNext() & next()) as it is not mentioned in the code any where...




In my opinion what is going on is a simple for loop. But using an Iterator object you get the same result, and you are using hasNext() and next() methods.



Hope it helps
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya I got it, Thanks Victor for such a nice example
 
Victor Fernandez
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sunil langeh wrote:Ya I got it, Thanks Victor for such a nice example



Cool
 
reply
    Bookmark Topic Watch Topic
  • New Topic