Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q26 Exam Marcus03

 
Shiwani Aggarwal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is true -
The elements in a Java array can only be of primitive types, not objects. Why this is wrong?
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi:
arrays can hold objects and primitives. It depends on the decleration type
Object[] a = new Object[] //creats array of objects
int[] b = new int[] // creats array of integers
However, you can't assign a primitive type array to an Object type array.
b = a // compiler error
a = b // compiler error

and so on
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If arrays could not hold Objects it would not be possible to create an array of Strings.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic