Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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 ?