Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

is Array in java are Object?

is Array in java are Object?
int a[]=new int[10];
new will allocate memory. but int is a type not an Class ?
please help me......
[156 byte] By [thennam] at [2007-11-11 7:40:57]
# 1 Re: is Array in java are Object?
The java compiler treats arrays as objects with a few basic methods and one public final value: length. There is no mystery :cool:
sjalle at 2007-11-11 22:37:43 >
# 2 Re: is Array in java are Object?
new will allocate memory. but int is a type not an Class ?

You would be surprised to see this. ;)

class Test {
public static void main(String[] args) {
System.out.println(int.class.getName());
}
}
aniseed at 2007-11-11 22:38:43 >
# 3 Re: is Array in java are Object?
You mean that this indicates that int is a class ? The class method here is used on the type definition, not a class instance.
So, this does not compile:

class Test {
public static void main(String[] args) {
int x=5;
System.out.println(x.class.getName());
}
sjalle at 2007-11-11 22:39:41 >
# 4 Re: is Array in java are Object?
int x=5;
System.out.println(x.class.getName());

x is not a object.
jetbrains at 2007-11-11 22:40:41 >
# 5 Re: is Array in java are Object?
Exactly, neither is int. And an object is not a class, it is an instance of a class.
sjalle at 2007-11-11 22:41:40 >
# 6 Re: is Array in java are Object?
is Array in java are Object?

int a[]=new int[10];

new will allocate memory. but int is a type not an Class ?

please help me......

Object is aarray
boolean b = object.getClass().isArray();
if (b) {
// object is an array
}
jetbrains at 2007-11-11 22:42:44 >