J
jtl.zheng
the codes:
-------------------
Object[] stuff = new Object[5];
stuff[0] = "eggs";
stuff[1] = new StringBuffer( "flour" );
stuff[2] = 3.56;
stuff[3] = 'c';
stuff[4] = 123;
stuff[0]="33";
for( int i=0; i<stuff.length; i++ ) {
System.out.println( stuff );
}
------------------
It seems odd.....
followings is what I guest. please tell me whether it's correct, thank
you very much
1:
what I think is because that the Object Class is any class's
superClass, so it can point to any type (right?), but in these codes it
only have Object Class's interface, not the interface which it point
to.
is it right?
2:
stuff[0]="eggs"
in this sentence,the JVM create a String object(right?), although it's
a String object and of course it has all the String object's
interface, but what the reference(stuff[0]) can access is only the
Object Class's interface.not the String interfaces(just like
concat(),charAt()....)
is it right?
3:
stuff[0]="eggs"
System.out.println( stuff[0] );
and when print it,the print function call stuff[0]'s toString()
function,and this toString() is the String object's , not the Object
Class's
is it right?
thank you very much
JTL
-------------------
Object[] stuff = new Object[5];
stuff[0] = "eggs";
stuff[1] = new StringBuffer( "flour" );
stuff[2] = 3.56;
stuff[3] = 'c';
stuff[4] = 123;
stuff[0]="33";
for( int i=0; i<stuff.length; i++ ) {
System.out.println( stuff );
}
------------------
It seems odd.....
followings is what I guest. please tell me whether it's correct, thank
you very much
1:
what I think is because that the Object Class is any class's
superClass, so it can point to any type (right?), but in these codes it
only have Object Class's interface, not the interface which it point
to.
is it right?
2:
stuff[0]="eggs"
in this sentence,the JVM create a String object(right?), although it's
a String object and of course it has all the String object's
interface, but what the reference(stuff[0]) can access is only the
Object Class's interface.not the String interfaces(just like
concat(),charAt()....)
is it right?
3:
stuff[0]="eggs"
System.out.println( stuff[0] );
and when print it,the print function call stuff[0]'s toString()
function,and this toString() is the String object's , not the Object
Class's
is it right?
thank you very much
JTL