This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: can we cast an array ?
 
Similar Threads
Can I caste Object[] to String[]?
Upcasting from Class to interface Problem
Question about instanceof
Curious about an answer explanation..
Difference between Instance, Object and reference