+ 1

Is it possible to have array of object in java?

1st Feb 2020, 9:10 AM
Eyasu kibru
Eyasu kibru - avatar
7 odpowiedzi
+ 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]; }
1st Feb 2020, 9:31 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 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.
1st Feb 2020, 9:29 AM
Avinesh
Avinesh - avatar
+ 1
like this ? Object[]arrayOfObj = new Object[5]
1st Feb 2020, 9:23 AM
Taste
Taste - avatar
+ 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.
1st Feb 2020, 10:21 AM
Avinesh
Avinesh - avatar
0
Sorry it is by mistake
1st Feb 2020, 10:22 AM
Eyasu kibru
Eyasu kibru - avatar
0
Now correct your mistake.
1st Feb 2020, 10:24 AM
Avinesh
Avinesh - avatar
0
I didn't down it i marked it as best answer
1st Feb 2020, 10:26 AM
Eyasu kibru
Eyasu kibru - avatar