Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hello-- Question on Return types

 
Eric Warner
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy yall,

This is my first post and I would like to say that while lurking here for a while now, I am very impressed with the community and the support provided here. HUGE thanks to all that is making this possible. Also, thank you Kathy and Bert for all your books, interactive and interesting should be required whenever Comp Sci is the subject.

My question is from the K&B book page 344-345 #19

Question: which of the following code fragment inserted in "insert code here" will not compile?

Answer D & F
Explanation F returns an primitive, not an object, D is a reference to a char primitive

Why not also C & E ?

Thanks for any responses.

( tags added)
[ November 14, 2004: Message edited by: Barry Gaunt ]
 
Toms Liepins
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Arrays are actually Objects in Java. In fact, you can even do this:

The code above will make compiler happy. That's the case for C. As for E, here you have a multidimensional array (array of arrays). Hence, c[1] is a reference to another array. Note that you can't return c[1][0], as this would return a primitive.

I would suggest to re-read a chapter on Java fundamentals (arrays), I'm sure K&B book has some decent info on this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic