• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 76394
364
  • 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
 
I brought this back from the farm where they grow the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic