Terrific question Tu Ran, I'll add this to my treasure chest ... it made my head hurt
This question started off innocently enough, but got more and more hairier as I pondered the possibilities!
I not sure what 'new Object[0]' returns? But let me take a crack at answering your posting!
1) oa1 is a reference to an object
2) oa2 is a reference to an object
the reason you can get away with these funny assignments to oa1 and oa2 has to do with the fact that an array in
java is consider to be 'object', in fact it's a sub-object of class Object
proof that an array is a sub-object of class Object
class A {}
A a1 = new A[10]; // won't compile
A a2 = (A) new A[10]; // type casting doesn't help
A a3 = (A)(Object)new A[10]; // this works!!!
why does a3 compile while a2 fails? because we need to upcast and then down cast!
For example, given this class hierarchy
class A extends Object {}
class B extends Object {}
Object a = new A(); // this is valid
Object b = new B(); // this is valid
A a = new B(); // won't compile
A a = (A)(Object) newB(); // this will compile , need to upcast then downcast
Try it!
3) oa3 is an array of references to objects of class Object (incidentlly this array gets initialized and reports a size of zero!)
4) xx is just a static reference which get assigned a default value of 'null'
Can anyone explain what's going on with reference 'o3a'? and what 'new Object[0]' returns? Curious to find out!
[ March 02, 2002: Message edited by: Rajinder Yadav ]