Each class variable, instance variable, or array component is initialized with a default value when it is created. For example;
int[] intArray = new int[10];
This allocates the memory for an array of size 10. This size is immutable.
Java populates our array with default values depending on the element type - 0 for integers, false for booleans, null for objects, etc. Let's see more of how we can instantiate an array with values we want.
The slow way to initialize your array with non-default values is to assign values one by one:
Answer is B.
To test:
public static void main(String[] args) {
int numbers[];
numbers = new int[2];
numbers [0] = 10;
numbers [1] = 20;
numbers = new int [4];
numbers [2] = 30;
numbers [3] = 40;
for (int x : numbers) {
System.out.println(" " + x);
}
}
The correct one is B, because a new reference is given to the numbers list, which overwrites the old one and 30 is added to position 2 and 40 to position 3 of the list, as it was reset, position 0 and 1 had no numbers, so they won the value of 0 because when an int has no reference to a number, 0 is given for the pattern, so when printing the list it outputs "0 0 30 40"
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
mvpVN
Highly Voted 6 years, 3 months agoMPignaProTech
Most Recent 8 months agofvelazqueznava
1 year, 8 months agoakbiyik
2 years, 7 months agocarloswork
2 years, 7 months agoiSnover
2 years, 9 months agonesreenmhd123
4 years, 11 months agopg13
4 years, 11 months agoSamAru
5 years agov323rs
5 years, 5 months agomuksa
5 years, 6 months agorasifer
5 years, 11 months agopawankalyan
6 years ago