Click to See Complete Forum and Search --> : is Array in java are Object?
thennam
01-07-2006, 12:45 PM
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.......
sjalle
01-08-2006, 11:31 AM
The java compiler treats arrays as objects with a few basic methods and one public final value: length. There is no mystery :cool:
aniseed
01-10-2006, 08:46 AM
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());
}
}
sjalle
01-10-2006, 08:56 AM
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());
}
jetbrains
01-10-2006, 11:41 PM
int x=5;
System.out.println(x.class.getName());
x is not a object.
sjalle
01-11-2006, 03:33 AM
Exactly, neither is int. And an object is not a class, it is an instance of a class.
jetbrains
01-12-2006, 08:32 AM
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
}
devx.com
Copyright Internet.com Inc. All Rights Reserved