• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Object Ref

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will happen if run the following code?

1:Boolean[] b1 = new Boolean[10];
2:
3:boolean[] b2 = new boolean[10];
4:
6:System.out.println("The value of b1[1] = " +b1[1]);
7:System.out.println("The value of b2[1] = " +b2[1]);

A) Prints "The value of b1[1] = false"
"The value of b2[1] = false".

B) Prints "The value of b1[1] = null"
"The value of b2[1] = null".
C) Prints "The value of b1[1] = null"
"The value of b2[1] = false".
D) Prints "The value of b1[1] = false"
"The value of b2[1] = null".

I think the answer should be B. Coorect me if i am wrong.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you compile and run it?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All arrays are initialized automatically. object references are initialized to null and boolean values are initialized to false so i think C is right.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rolf.
 
Liar, liar, pants on fire! refreshing plug:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic