aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array question" Watch "array question" New topic
Author

array question

Douglas Chorpita
Ranch Hand

Joined: May 09, 2006
Posts: 97
In Java, an Monkey array can be assigned to an animal array.

The following code is legal:




Java doesn't allow this, however. Why? Is "Object" a special case?



SCJP 1.4 - 95%
Andy Morris
Ranch Hand

Joined: May 30, 2004
Posts: 78
Both code snippets are completely legal and will compile and run without errors. I don't know how you reached your observation.

The only arrays where implicit casting is not permitted are arrays referencing primitives types.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Andy Morris:
Both code snippets are completely legal and will compile and run without errors. I don't know how you reached your observation.

The only arrays where implicit casting is not permitted are arrays referencing primitives types.


Confirmed.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Douglas Chorpita
Ranch Hand

Joined: May 09, 2006
Posts: 97
Sorry. My fault.

I was doing a bunch of tests, all in one file.

I had created a class called "Object" in my own package. I know this is stupid, but I wanted to see (with my own eyes) that a class called "Object" would compile and extend "java.lang.Object".

This is why I got the error.

Thanks for the help!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array question