aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP array problem 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 "SCJP array problem" Watch "SCJP array problem" New topic
Author

SCJP array problem

Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
Dear friends,

Kindly find time to guide me through the following example of K&B


My problem is with line:
int [] b= (int []) a[1];
It is clear that though a is a two dimensional array, yet a[1] is a single dimensional array. Therefore why explicit casting was required here. Why the following line would not have been proper :
int [] b = a[1];
Please explain.
While preparing, i got struck down by lot of self test questions in this (Assignments) chapter, though could understand them later on but at first go could make the correct choices. This sort of has depressed me. Kindly help.


Anand Shrivastava
SCJA
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Anand Shrivastava:
...
My problem is with line:
int [] b= (int []) a[1];
It is clear that though a is a two dimensional array, yet a[1] is a single dimensional array. Therefore why explicit casting was required here. Why the following line would not have been proper :
int [] b = a[1];
...

Did you try compiling and running this without the explicit cast?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Gaurav Bhatia
Ranch Hand

Joined: Jan 01, 2007
Posts: 49
I tried and it worked without the explicit cast also.

I used ->

PS: Using JDK 1.5 and Eclipse as IDE


~Gaurav<br />SCJP5
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Originally posted by Gaurav Bhatia:
[QB]I tried and it worked without the explicit cast also.



If you tried and it Did work, then it's Perfectly fine with out the cast.
What seems the problem?

Having something extra that is not required doesn't make it wrong.
You just need to know when it's right and when it is not so that you can point out when it will have an error and when it won't .
Coz that's what the exam is all about....


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
 
Consider Paul's rocket mass heater.
 
subject: SCJP array problem