File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Hello-- Question on Return types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Hello-- Question on Return types" Watch "Hello-- Question on Return types" New topic

Hello-- Question on Return types

Eric Warner

Joined: Nov 14, 2004
Posts: 3
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

Joined: Nov 02, 2004
Posts: 21
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.
I agree. Here's the link:
subject: Hello-- Question on Return types
It's not a secret anymore!