+ 1
Is it possible to have array of object in java?
7 Answers
+ 2
Yes it's possible.
Proof:
Arrays are objects themselves in Java
Consider the following
int [ ] arrayOfArrays = [5][5];
We crated an array that holds an array of primitives
Proof2:
instead of a primitive types, use objects to declare and initialise an array like so:
class Person{
private String name;
private int age;
}
class Main{
public static void main(String[] args) {
Person[ ] arrayOfPersons = new Person[5];
}
+ 4
Yes it is possible.
Taste has given you an example.
You can replace the Object class with any user defined class and create an array of its objects.
+ 1
like this ?
Object[]arrayOfObj = new Object[5]
+ 1
Now why would you down vote my answer. If you didn't find an answer in my comment then leave it as it is.
0
Sorry it is by mistake
0
Now correct your mistake.
0
I didn't down it i marked it as best answer