This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes can we cast an array ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we cast an array ?" Watch "can we cast an array ?" New topic
Author

can we cast an array ?

saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
I have the following code :




And this code works perfectly well, which means that i can put a honda in car reference and then cast it and put it in another honda reference. But if i do the same thing with Array it does not work . i get a compiler error. so if i change my car tester class like this :




so can anyone tell me whether casting is possible with arrays? if so then how can i correct my code ?



saima.






SCJP 6.0 (86%) SCWCD 5 (94%)
Rok Štelcer
Ranch Hand

Joined: Nov 03, 2009
Posts: 101
Hi,
saima kanwal wrote:
so can anyone tell me whether casting is possible with arrays?

Sure it is.

saima kanwal wrote: if so then how can i correct my code ?

Change the following line:
to

Regards,
Rok


SCJP, SCWCD
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
Thanks Rok.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we cast an array ?