File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes illegal array reference assignments... 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 "illegal array reference assignments..." Watch "illegal array reference assignments..." New topic
Author

illegal array reference assignments...

sonia jaswal
Ranch Hand

Joined: Jun 01, 2007
Posts: 42
in K&B's book on pg 225, 3rd chapter, fig 3.6.... the illegal reference assignments whcih are given below... the last one... that is...
myCats[0][1]= moreCats;
the explaination given for this is "cant assign an array object to a nonarray refernce"... but in the code moreCats is a reference variable, not an array object... so should it be moreCats[0]....

thanks..
Thirugnanam Saravanan
Ranch Hand

Joined: Dec 13, 2007
Posts: 81
myCats is a 2-D array object of Cat (i.e., Cat[][]).
moreCats is a 1-D array object of Cat (i.e., Cat[]).

In this case (myCats[0][1]= moreCats ) ,they are trying to assign a Cat[] (Right hand side value i.e moreCats) to a Cat object (left hand side value i.e., myCats[0][1]).

Would have been valid if the assignment is

myCats[0][1]= moreCats[0];
[ December 22, 2007: Message edited by: Thirugnanam Saravanan ]

Saravanan
SCJP 5.0(98%), SCWCD 5.0 (100%), OCA
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: illegal array reference assignments...
 
Similar Threads
About Object class problem?
Please explain me Array Reference Assignments for Multidimensional Array
Arrays
arrays & final
Confusion with operator '=' right associativity