Which of the following statements are true?
1) The elements in a Java array can only be of primitive types, not objects
2) Arrays are initialized to default values wherever they are created
3) An array may be dynamically resized using the setSize method
4) You can find out the size of an array using the size method
Answer :
2) Arrays are initialized to default values wherever they are created
You can find the size of an array using the length field. The method length is used to return the number of characters in a String. An array can contain elements of any type but they must all be of the same type. The size of an array is fixed at creation. If you want to change its size you can of course create a new array and assign the old one to it. A more flexible approach can be to use a collection class such as Vector.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment