• 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

Threads

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Just going through the sample questions got from web.
Can someone explain me the result of the following program, placed at:

http://picasaweb.google.com/sujathalooks

The Answer for that question is F.

Thanks in advance.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you provided will yeild the answer of 0 2 4 6 as mentioned by the option 'f'

Look at the main method.The first line created an array of size 4 and type Computation.
Now each element of the array is used to create a new object of computation by passing the index value of the array as parameter.
Thus we have 4 computation objects calling the constructor once for each.It also means we will have 4 instance variables of type isComplete,num and result.global num is being shadowed by the local num in the constructor so,the global num is explicitly given the value passed by local num through the keyword 'this'.
When the start() is called it makes a call to run().here value of result is set.
lastly in the print statement(with the use of new for:each loop),the getResult is called which returns the value of result which is printed.

Hope this solves your query.
 
Sujatha Musunuri
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jitendra Jha,

I got it now...Thanks alot for your explanation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic