• 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

Program Output

 
Greenhorn
Posts: 12
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain why is the output -434 ?
From Kathy & Bates



The explanation given in the text is as:
1.Overloaded var-args are chosen last [OK]
2.Arrays are objects [then for sifter(ba), shouldn't the output be 4, after all its the same as "sifter(aa)"]
3.An int can be boxed to an Integer and then "widened" to an Object.

Thank you.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please always tell us where such examples come from.
Write down the values of the fields in that B class. That would appear to be the String s. Work out which methods are called, in which order. Are you calling the sifter() method with Objects, As or Bs or what? Remember that sort of qwuation will have special features to confuse you.
 
Achint Verma
Greenhorn
Posts: 12
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry but this is a direct question from Kathy & Bates. From the self test questions.
 
Ranch Hand
Posts: 635
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this please:

http://stackoverflow.com/questions/8780235/sc-java-programmer-6-exam
 
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic