Q: What is the output of the below Java program? int[] marks = {35,65,95}; System.out.print(marks.length + "," + marks[1]);
Solution: Array index starts with Zero (0). So marks[1] represents the second element.
Q: What is the output of the below Java code snippet? int[] balls = {}; System.out.print(balls.length);
Solution: no solution
Q: Which is the correct way of knowing Array Size in Java?
Solution: "length" is a field, not a method. So, parentheses are not required.
Q: What is the output of the below Java program with arrays? String[] colors = {"RED";"YELLOW";"WHITE"}; System.out.print(colors[2]);
Solution: Array elements must be separated with Comma(,)s.
Q: What is the output of the below Java program with arrays? public class Polo { public static void main(String args[]) { String[] computer = {"RAM","HDD","MOUSE"}; String[] parts = {computer[0],computer[2]}; System.out.print(parts[1]); } }
Solution: no solution
Q: What is the output of the below Java program? int ages[3] = {25, 27, 30}; System.out.println(ages[1]);
Solution: We should not mention the array size at the time of Shorthand Initialization. Error: Unresolved compilation problem: Syntax error on token "3", delete this token So make it like int ages[] = {25, 27, 30};
Q: We should not specify the array size if declaration and initialization are done at the same time. (TRUE / FALSE)
Solution: WRONG: int ary[2]={34,45}; RIGHT: int ary[] ={34,45};
Q: If an index of an element is N, what is its actual position in the array?
Solution: Array index starts with 0. So, an index of 6 means 7th position. An index of N means, N+1 position.
Q: An array in Java can be declared only of some predefined types. (TRUE/FALSE)
Solution: An array can be of any data type, primitive or Object type.
Q: The name of an array variable or identifier can start with ___.
Solution: no solution
You Have Score    | /10 |